Twig provides a dump
function for debugging variables in templates.
The dump
function outputs information about a template variable. The dump
function will not display anything unless twig_debug
is enabled.
To enable Twig debugging, find the twig.config parameters in your services.yml and set debug to true:
parameters:
twig.config:
debug: true
If your template has a title
variable available, the following will dump its contents to your template:
{{ dump(title) }}
To dump all available variables and its contents in a template, add the following to your template:
{{ dump() }}
To dump only the available variable keys use:
{{ dump(_context|keys) }}
There are additional global variables available in all Twig templates:
_self
references the current template and contains advanced information about a template, i.e. the compiled template class name and information about the Twig environment._context
references the current context and contains all variables passed to the template such as variables sent from theme(), prepared by preprocess, or set in the template. Adding{{ dump() }}
without specifying a variable is equivalent to{{ dump(_context) }}
._charset
references the current charset.