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.
Create a settings.local.php file in sites/default/settings.local.php
In settings.local.php make sure this exists
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) { include $app_root . '/' . $site_path . '/settings.local.php'; }
In settings.local .php add
$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml'
Add this after the step 3 code
$settings['cache']['bins']['render'] = 'cache.backend.null'; $settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
Clear cache with `drush cr` or the performance page in the admin.
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