Drupal 8: Disable Twig Cache During Development

Drupal 8: Disable Twig Cache During Development

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.local.php make sure this exists

    1. if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
       include $app_root . '/' . $site_path . '/settings.local.php';
       }
  3. In settings.local .php add

    1. $settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'
  4. Add this after the step 3 code

    1. $settings['cache']['bins']['render'] = 'cache.backend.null';
      $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
  5. Clear cache with `drush cr` or the performance page in the admin.

  6. 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

 

Drupal 8 Module: Twig Field Value

Drupal 8 Module: Twig Field Value