Community Documentation

Debugging variables in Twig templates

Last updated February 19, 2013. Created by Cottser on February 3, 2013.
Log in to edit this page.

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. Currently the value of twig_debug is hardcoded pending resolution of #1843034: Make Twig settings configurable.

If your template has a title variable available, the following will dump its contents to your template:
{{ dump(title) }}

To dump all available variables in a template, add the following to your template:
{{ dump() }}

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.

See Twig's dump function documentation to learn more about the dump function.

Page status

About this page

Drupal version
Drupal 8.x
Audience
Designers/themers, Programmers
Level
Intermediate
Keywords
Twig
Drupal’s online documentation is © 2000-2013 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here