Description
Steps
-
install devel module
-
turn on the debugger and use this code in a twig template that you want to debug
{{ devel_breakpoint() }}
Find out how to turn on the debugger on the same page linked in this solution's description.
-
use the provided debug information
You will notice that the code doesn't actually break inside the twig template. The exact code where the execution breaks varies by environment, but in this case it breaks in
devel/src/Twig/Extension/Debug.php
in the
Debug::breakpoint
method.
On the variables debug pane, you will have access to all of the variables available in the twig template.
The "$context" variable is actually the "_context" variable available in twig templates, that you can dump inside the template. It contains all the other variables available to the template and may be what you are mostly interested in.
Notes
Other Drupal modules offer similar functionality, like Twig Xdebug.