Last updated May 2, 2016. Created on February 2, 2013.
Edited by heykarthikwithu, serg2, japo32, wesruv. Log in to edit this page.

The Twig templating engine offers a debug tool.

The Drupal 8 implementation also adds an additional tool that allows you to locate the template that outputs the markup.

Enable debugging

You enable Twig Debugging in sites/default/services.yml.
(If services.yml does not yet exist; copy and rename it to services.yml.)

Set the debug variable to true.

    debug: true 

In firebug make sure that "Show Comments" is enabled:

Firebug setting for twig debug

Automatic reloading Twig templates are compiled

Twig templates are compiled to PHP classes on disk for better performance, but this means by default your templates are not refreshed when you make changes. To enable automatic reloading of Twig templates, enable debug in services.yml. For more information, see

Printing variables

{{ dump() }}
{{ dump(var) }}

If you have Devel's kint submodule you can get an accordion display of the variables available to twig with:

{{ kint() }}

More debugging options can be found in the next section.

twig-debug.png77.28 KB

Looking for support? Visit the forums, or join #drupal-support in IRC.


Infanty’s picture

If you do not set module Devel - add setting.php:
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/default/services.yml';

If Devel module is installed - add setting.php:
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/default/services.yml';

To use the {{ kint() }} - set Devel Kint module from the Devel.

gollyg’s picture

Note, similar functionality was back-ported to Drupal 7. It can be enabled by uncommenting:

$conf['theme_debug'] = TRUE;

from your settings.php file