Drupal and Web Development Tidbits

Disable Twig Cache During Development

March 6, 2021

Written by: Jon Kamke

I discovered that changing the Twig cache settings in the services.yml file did not work, at least with a Pantheon Drupal site. Thanks to the steps found on www.drupal.org/node/2598914 I was able to figure out how to disable Twig caching for front-end development. I was developing on the Pantheon platform and the following worked for me to disable Twig caching so I didn’t have to continuously run cache rebuild.

  1. Create a settings.local.php file in sites/default/settings.local.php

  2. In settings.php make sure this exists

if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
  include $app_root . '/' . $site_path . '/settings.local.php';
  1. In settings.local.php add
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'
  1. Add this after the step 3 code
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
  1. Clear cache with drush cr or on the performance page in the admin.

  2. Making changes in a Twig template should now be reflected after a page reload without having to clear the cache first.

Source: https://www.drupal.org/node/2598914