Problem/Motivation
Variables within twig templates can still be very interesting, they can be objects, render arrays and strings.
Render arrays itself can be #type, or #theme or have #theme_wrappers, etc.
Proposed resolution
Create a twig function to tell information about a variable:
{{ get_variable_information(pager_next) }}
This is a "render array".
It has the following variables defined:
* url, text
It has #type = link and two #theme_wrappers
or something like that.
It is introspection within Twig.
Remaining tasks
* Write a proof-of-concept approach
User interface changes
API changes
Related Issues
* #1804998: Add LadyBug from Symfony to Core to allow debugging variables within templates
Original report by jenlampton
It would be great if we could give our front-end devs a way to see all available variables in any given template. Something along the lines of the token UI that would show top-level items, and then allow a drill-down into each one (if available) would be awesome.
I understand something like this may be possible now that we are using Twig and Objects!
Let's make some front-end devs happy :)
marking as postponed till we get the engine working :)
Comments
Comment #1
psynaptic commentedExcellent idea! I would be happy to work on this when the time is right.
Comment #2
fabianx commentedHere are some ideas:
Here are some links for later reference:
http://drupal.org/node/1021556
http://drupal.org/sandbox/vackar/1806252
Comment #3
jenlamptonThink some progress has been made in #1805526: {{ _self }} in the frontend => How do I dump or debug things? towards this goal.
Comment #4
fabianx commentedIt is active!
Comment #5
buddaHaving read this and #1805526: {{ _self }} in the frontend => How do I dump or debug things? what is actually desired in the end?
On the other thread the following is mentioned:
or just
{{ dump() }}for the whole context.Are you wanting something more like the Krumo / kpr() command which does the collapsed drill-down data?
Comment #6
fabianx commentedYes, wanted some token like browser to drill down into variables, but will do so in contrib probably.
Comment #7
fabianx commentedMoving to core and making it meta.
Comment #7.0
fabianx commentedUpdate issue
Comment #8
star-szrTagging.
Comment #9
soulston commentedThere is a similar discussion about dumping out variables going on here https://drupal.org/node/1804998 (Add LadyBug from Symphony to Core to allow debugging variables within templates)
Comment #9.0
soulston commentedAdd related issue
Comment #10
joelpittetAdding a relation to #2114563: Remove TwigReference with the help of 'without' filter replacing 'show'/'hide' functions. as it currently prevents dump() from doing anything useful along with other things.
Comment #11
star-szrI think this should be explored in contrib first. We do have some fairly nice things like the Kint module that is part of the Devel module in D8 contrib and I'm excited for other possibilities!
Comment #12
catchWe can add experimental support, or full support, for this, in a minor release.
Comment #16
chi commentedI just added an integration for Symfony VarDumper component to Twig tweak module. We may consider this as a proof of concept.
Comment #17
markhalliwellThe
{{ drupal_dump() }}function in Twig Tweak module isn't a "proof of concept" for this issue (read issue this issue and its summary).It's just a wrapper around
{{ dump() }}(which we already have). Thus, this module is actually duplicating (and confusing) existing functionality.This issue is, specifically, about providing better information about variables; not just "dumping them". In particular, and in regard to render arrays, the
#typeand#themehook used.This also doesn't change the state of #11, so setting back to postponed.
edit: updated link to correct comment number for why this issue is postponed.
Comment #18
chi commentedI agree the issue is not just about dumping.
Unfortunately existing functionality is not quite useful because it relies on pure PHP var_dump function.
Can you explain why? The issue is targeted against 8.4. What are we waiting for?
Comment #31
smustgrave commentedThank you for creating this issue to improve Drupal.
We are working to decide if this task is still relevant to a currently supported version of Drupal. There hasn't been any discussion here for over 8 years which suggests that this has either been implemented or is no longer relevant. Your thoughts on this will allow a decision to be made.
Since we need more information to move forward with this issue, the status is now Postponed (maintainer needs more info). If we don't receive additional information to help with the issue, it may be closed after three months.
Thanks!
Comment #32
smustgrave commentedFor this one the child issues are all closed so wonder what's next?
Comment #33
chi commentedI think this has been resolved in #3306864: Integrate Twig with Symfony VarDumper for improved debugging experience.