Discovering and Inspecting Variables in Twig Templates using {{ dump() }} function.
To dump only the available variable keys use: {{ dump(_context|keys) }}
Uncomment the line that contains the twig_debug setting.php
$settings['twig_debug'] = TRUE;
Beware of dump()
If you want to see all variables, but dump() results in exhausted memory because of recursion or the like, you can loop through _context to see all the keys in it:
<ol>
{% for key, value in _context %}
<li>{{ key }}</li>
{% endfor %}
</ol>
Then use a conditional to check (for example {% if loop.index == 2 %}), and dump that value only if necessary.
Devel has adopted a new library to print variables and it’s called Kint.
kint(), ksm()
- Add new comment
- 1680 views