"

Enabling Twig debugging

Enabling Twig debug mode can make theming much easier: it adds comments to the output stating which template file is being used, enables the twig dump() command, and disables some caching so that changes to Twig files usually show up right away.

However, you never want to enable Twig debugging on a shared server: the data it outputs can be used by malicious viewers of the site to glean sensitive information about the site, the administrator’s password hash, etc. Further, the performance overhead incurred makes the site easier to take down by flooding with traffic.

Enabling Twig debugging usually involves making a change to the site’s base services.yml file (usually located in /web/sites/default). However, to prevent human error (i.e.: accidentally committing a change to enable Twig debugging), we’ve made it so you can override services.yml with a services.local.yml file, which is ignored by git.

To enable twig debugging:

  1. Fix Drupal’s sites directory hardening: chmod u+w web/sites/default web/sites/default/*
  2. Copy example.settings.local.php to web/sites/default and rename the file to settings.local.php: cp web/sites/example.settings.local.php web/sites/default/settings.local.php
  3. Override the development.services.yml in web/sites with that in root: cp development.services.yml web/sites/development.services.yml
  4. Flush Drupal cache: lando drush cr