What is Twig debugging in Drupal?

Twig debugging is a developer feature that adds HTML comments to rendered pages showing which templates are being used. Enable it in sites/default/services.yml by setting debug to true under twig.config.

Once enabled, view any page and inspect the source. You will see comments like FILE NAME SUGGESTIONS and BEGIN OUTPUT that tell you which templates Drupal considered and which one was actually used.

This is invaluable when you want to override a template but are not sure what to call your override file. It also helps when debugging unexpected layouts. Remember to turn debugging off in production, since it adds overhead and leaks information about your site structure. Most developers keep it enabled on local and staging environments and disabled on live sites.

Facebook
Twitter
LinkedIn
Pinterest