Make Debugging Twig easier

Created on 28 December 2016, almost 8 years ago
Updated 23 January 2023, almost 2 years ago

Problem/Motivation

Developers routinely enable settings for Twig development by editing development.services.yml. However this is not convenient as it gets overwritten from core scaffold files with each Drupal composer update. We should provide a better way to do it.

There are 3 relevant Twig settings.

  1. auto_reload: always useful in development
  2. debug: often useful, but causes major bugs on some sites, see 🌱 [META] twig debug can break parts of site Active
  3. cache: should always be enabled even in development. This setting is already enabled by default so no changes are needed.

Proposed resolution

  1. Add auto_reload to development.services.yml because it's always useful in development.
  2. Create a new file twig-debug.services.yml specifically for the Twig debug setting.
  3. Reference this new services file in sites/example.settings.local.php, below the line of code where development.services.yml is referenced. Leave the reference commented out with a note explaining the potential dangers and implications of enabling theme debugging.
    /**
     * Enable Twig debugging services.
     *
     * Enabling Twig debugging is not recommended in production environments and
     * can break parts of Drupal. See https://drupal.org/i/2914733 for details.
     */
    $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/twig-debug.services.yml';
    

    For the website themer, this code is more or less analogous to adding $config['theme_debug'] = TRUE; option in Drupal 7 settings.php file . Optionally, a CR could be added to describe this difference between D7 / D8.

Feature request
Status

Needs work

Version

10.1

Component
Theme 

Last updated about 2 hours ago

Created by

🇭🇺Hungary gpap

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Not all content is available!

It's likely this issue predates Contrib.social: some issue and comment data are missing.

Production build 0.71.5 2024