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 CreditAttribution: psynaptic commentedExcellent idea! I would be happy to work on this when the time is right.
Comment #2
Fabianx CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: Fabianx commentedYes, wanted some token like browser to drill down into variables, but will do so in contrib probably.
Comment #7
Fabianx CreditAttribution: Fabianx commentedMoving to core and making it meta.
Comment #7.0
Fabianx CreditAttribution: Fabianx commentedUpdate issue
Comment #8
star-szrTagging.
Comment #9
soulston CreditAttribution: 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 CreditAttribution: 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 CreditAttribution: 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
#type
and#theme
hook 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 CreditAttribution: 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?