Postponed
This issue is postponed on 8.1.x being open for development.
Problem/Motivation
Front end devs need a way to be able to see what they are working with, and we all know how much they hate digging through render arrays. Since we still have the ARRAYS OF DOOM in Drupal 8, we need to figure out how we're going to provide debugging features for Twig templates.
Proposed resolution
We have several options:
- clean up the render array and make a friendly version for inspecting
- use something like ladybug from symfony/twig-land
- other?
Remaining tasks
TBD
User interface changes
None
API changes
TBD
Related Issues
Original report by @psynaptic
Twig provides it's own {{ dump(variable) }}
function enabled via:
$twig->addExtension(new Twig_Extension_Debug());
Devel module has some very useful debugging functions such as dpm
, kpr
, etc. which it would be handy to have available.
Devel function registrations should live in devel module but we need to provide a way for core to enable debugging of templates using the Twig {{ dump(variable) }}
method.
Comments
Comment #1
Fabianx CreditAttribution: Fabianx commented+1 to this: How can we set a site from dev to production mode or vice versa is the general question here?
So that we can set debug => TRUE | FALSE depending of state.
Comment #2
soulston CreditAttribution: soulston commentedWhile devel module is great there is a lot of stuff in krumo which might put off a themer.
This is just a suggestion but how about adding a simple output of all available twig items in a tab, much like devel does for it's output?
If we add a hook_permission for this you wouldn't need to remember to disable this between dev, staging and production.
Comment #3
Fabianx CreditAttribution: Fabianx commentedhook_permission is an excellent suggestion.
Comment #4
eojthebraveI like the hook_permission() idea but I'm not sure that adding it as a "tab" is the right approach since there are a lot of template files that are not directly associated with something that exists in the menu system and thus there would be no where on the page to render the tab.
Comment #5
steveoliver CreditAttribution: steveoliver commentedI'm moving this from the Twig sandbox to the Core queue to get some eyes on it. I don't actually expect we'll do this in core at the moment, but rather likely within Devel or other contrib project.
@bzitzow in irc pointed out https://github.com/raulfraile/LadybugBundle, a Symfony2 bundle for Ladybug library, "the Simple and Extensible PHP Dumper" which looks like it'd be a little more useful than krumo as LadyBug provides references to API docs for known Symfony2 classes.
Comment #6
steveoliver CreditAttribution: steveoliver commentedAssigning to myself.
Comment #7
soulston CreditAttribution: soulston commented+1 for for LadybugBundle, let me know if you need any help with this.
Comment #8
steveoliver CreditAttribution: steveoliver commentedWe don't need the bundle--only the library. However, I'm having an issue with "phpdocumentor/reflection-docblock 2.0.0a3" getting the library installed from either the core composer.json or a core module's own composer.json. Anyone (soulston?) familiar with Composer feel like taking a stab at this? Unassigning myself.
I get the same error in either case:
Comment #9
soulston CreditAttribution: soulston commentedI'm not that familiar with composer either but I'll take a look at it and report back.
Comment #10
alexdoronin CreditAttribution: alexdoronin commentedMy experience (I don't familiar with the Symfony and Composer):
1. I installed LadybugBundle. Debugging (ladybug_dump) still not working.
2. Ok. I tried to install Ladybug (https://github.com/raulfraile/Ladybug).
Fisrt time I got the same message ("The package is not available in a stable-enough version according..."),
than I added "minimum-stability": "dev" in the composer.json.
3. In this way process has started, but after some time:
I think, this means that I don't have enough memory in the server.
Because, for the first time I had the same problem for LadybugBundle, and after I changed server memory from 256 to 512Mb, the problem was solved. Now I have no way to increase memory a little more.
Comment #11
Fabianx CreditAttribution: Fabianx commentedChanging title to reflect reality of this issue.
This is part of:
#1783134: [META] Make it possible to inspect twig variables and get information about objects and render arrays
Comment #12
alexdoronin CreditAttribution: alexdoronin commentedI've increased memory to 1Gb (https://drupal.org/node/1804998#comment-7686117) and now I get:
This is a dead-end.
Comment #13
soulston CreditAttribution: soulston commentedthanks @galactik
Moving this on, what options do we have here:
What does symfony do for this - as suggested it looks like they just use "dump" (http://symfony.com/doc/current/book/templating.html#debugging), but obviously this is not drillable. Do any symfony people out there have any suggestions?
Also while "LadyBug provides references to API docs for known Symfony2 classes", is this really going to be of help to themers?
I agree it would be much better to have one tool that we all use but not the detriment of failing to achieve the goal here - let themers know what is available to use.
Comment #14
star-szrComment #15
star-szrDidn't mean to remove that tag.
Comment #16
jenlamptonsummary update
Comment #17
raulfraile CreditAttribution: raulfraile commentedHi, I am Raul Fraile, I created the ladybug library and the Symfony2 bundle.
Both the library and the bundle are now stable after a huge refactoring, sorry for all the troubles while installing alpha versions. I would be really happy to help as much as possible to integrate the library/bundle in Drupal, let me know what I can do. The library allows customized themes, so a Drupal theme could be created using Twig.
Some examples of the new version of the lib: https://github.com/raulfraile/ladybug/blob/master/doc/examples.md
Cheers!
Comment #18
markhalliwellHi @raulfraile! I am very, very excited to hear this! I'd love to chat with you about this in #drupal-twig in IRC when you can get a chance! Thanks for such awesome work!
Comment #19
raulfraile CreditAttribution: raulfraile commentedGreat! What time works for you?
Comment #19.0
raulfraile CreditAttribution: raulfraile commentedsummary update
Comment #20
donquixote CreditAttribution: donquixote commentedWondering: If we use either KrumoNG or Ladybug or Kint in D7, and also the nice DPQ, then we will need
- autoload capabilities for PSR-0 or equivalent.
- PHP 5.3 upwards for namespaces support.
- Maybe pull in the respective library via composer_manager?
So, would it make sense to start a new branch of D7 devel with added requirements and composer_manager?
Comment #21
markhalliwellNot really sure why I apparently assigned this to myself... :-/ Maybe @fubhy can tackle this ;) He seems interested.
Comment #22
star-szr@donquixote - not sure how that is related to debugging in the D8 theme layer to be honest.
Comment #23
donquixote CreditAttribution: donquixote commented@Cottser: Sorry I just realize I posted this in the wrong issue. I think I wanted to post this somewhere in the Devel queue.
Comment #24
star-szrPostponed until at least 8.1.x, this can be added in contrib as well - see the Kint submodule in Devel.
Comment #25
joelpittetLet's move this to 9.x. There is a ladybug module for people who want to try it out and kint is in devel.
See which one people tend to prefer.
Comment #26
catchI think it's OK to have this against 8.1.x for now since it could go into a minor release (if not 8.1.x itself - agreed on seeing how this goes in contrib for a whle longer, so leaving postponed).
Comment #27
hass CreditAttribution: hass commentedComment #29
moshe weitzman CreditAttribution: moshe weitzman commentedFYI these modules are a bit challenging to integrate when BigPipe is enabled. Ideally this works together if this issue ever gets re-enabled. See #2678662-13: Ensure BigPipe does not break when HTML document contains CDATA sections or inline scripts matching certain patterns
Comment #30
nicrodgersComment #31
joelpittetBring down to normal as this is nice to have but I can't see the significant benefit over what devel provides with kint. Just a nice alternative.
Please let me know if I've missed something in that regard.
Comment #32
JacineI'm finding it impossible to get debug info from inside Twig templates. From my experience so far, most of the time
{{ kint() }}
is impossible to use. There are either too many instances, and it times out, and/or its location inline is unreadable or gets in the way of what I'm working with directly. When it does work, it's painfully slow and awkward. I need access to these variables either in the message area (preferably) or written to an external file/location.I'd love to try Ladybug, because I'm told it resolves some of these issues, but I cannot even get it installed. It requires Composer Manager, and I cannot complete the installation ("Your requirements could not be resolved to an installable set of packages."). This is not something I have control over ATM (likely due to contrib patches we have pending). It also sucks to have to install Composer Manager just to use it. From a theming perspective, I could care less about Composer, this is not a project dependency, but a debugging tool, and just want to get my front end work done, without having to understand and resolve a web of Composer and Drupal dependencies. I'm guessing having it in core would help with this part at the very least.
Bottom line for me: I currently depend 100% on the preprocess layer for variable discovery using
ksm()
, and have given up even attempting to use debugging functions from templates almost entirely.Comment #33
jibranWhat is the impact of #2191395: Make dpm() and friends pluggable (with Krumo, Kint, Ladybug etc) here?
Comment #34
JacineI did manage to get help installing (contrib) Ladybug. However,
ldpm()
and friends do NOT work within Twig templates. For anyone that comes across this, looking to install the Ladybug contrib module to get this functionality in Twig templates, you might not want to bother wasting your time.Comment #35
willzyx CreditAttribution: willzyx commented@Jacine I'm working on #2725395: Dumper system Part II: Add basic Twig debug support in the devel issue queue. Once committed every dumper plugin can be used for debug twig templates. Also opened #2707967: Add support for Devel dumper system for adding devel support in ladybug module
Comment #36
JacineOh, that's fantastic! Thank you @willzyx.
Comment #39
WebKings.caI'm having the same problem as Jacine. I'm getting an out of memory error when using kint in a twig template.
The workaround I have used is:
1) Enable Twig Debugging
2) Use {{ dump() }}
It will give the same output as kint, but without the fancy UI