Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Solution:
{{ dump() }}
displays all variables.
---
cant get {{_self}} to function in the frontend branch throws an error when used:
twig_Error_Runtime: An exception has been thrown during the rendering of a template ("Object of type "__TwigTemplate_6e62bf61c51b42082c46ee1f4d61501d" cannot be printed.") in "core/themes/stark/templates/system/breadcrumb.twig" at line 15. in Twig_Template->displayWithErrorHandling() (line 269 of /Users/mortendk/Dropbox/websites/drupal8twig/core/vendor/twig/twig/lib/Twig/Template.php).
Comments
Comment #1
Fabianx CreditAttribution: Fabianx commentedFor what do you need {{ _self }} printed?
Comment #2
mortendk CreditAttribution: mortendk commentedits nice to know what vars that are available ;)
else were kinda working in darkness arent we ?
right now im working on the breadcrumb function, so i wanted to know what the vars were called etc
Comment #3
Fabianx CreditAttribution: Fabianx commentedPlease use:
instead. That will give the vars available.
Leaving as active, so others can find it.
Comment #4
Fabianx CreditAttribution: Fabianx commentedYou can also use kpr, dpr, dsm, etc. if devel module for D8 is downloaded and enabled. psynaptic took care of that.
Comment #5
mortendk CreditAttribution: mortendk commentedawesome!!
Comment #6
anthonyR CreditAttribution: anthonyR commentedLifesaver, thanks!
Comment #7
jenlamptonCan we use this solution for #1783134: [META] Make it possible to inspect twig variables and get information about objects and render arrays?
marking as dupe.
Comment #8
Fabianx CreditAttribution: Fabianx commentedOthers need to find this issue, re-opening as a pure support request.
Comment #9
JohnAlbinThe issue summary says to use
{{ dump() }}
, while Fabian's comment #4 says to use{{ dump(_context) }}
. Are they equivalent? It's unclear.Comment #10
Fabianx CreditAttribution: Fabianx commentedThey are equivalent according to docs.
Comment #11
JohnAlbinThanks for the clarification. Then, I'll leave the issue summary as-is. :-)
Comment #12
steveoliver CreditAttribution: steveoliver commentedJohnAlbin:
{{ dump() }}
appears to use_context
by default;{{ dump() }}
outputs the same as{{ dump(_context) }}
for me.From Twig's docs on templates + a few inline notes from my observations:
_self
references the current template -- it contains variables about a template, i.e. its filename and available Twigblock
s;_context
: references the current context -- it contains variables for a template such as variables sent from theme(), prepared by preprocess, or set in the template;_charset
: references the current charset.Comment #13
webthingee CreditAttribution: webthingee commentedUntil there is a way to use dsm, dpr, kpr
I am starting to find that what works well for me is..
Comment #13.0
webthingee CreditAttribution: webthingee commentedAdd dump() function
Comment #14
BerdirThis was referenced in http://drupal.stackexchange.com/questions/98014/devel-dsm-function-in-dr....
Would be great if someone in here could provide a more complete and detailed answer about what's currently available and possible. Easier to find than an issue and can be moved into d.o documentation later on.
Comment #15
star-szrPosted an answer there, thanks @Berdir. See #2218949: Add Kint functionality to Twig templates, I hope we get tons of debugging options on contrib :)