Disable Drupal 8 Twig template cache during development

It usual when you are new to the Drupal 8 theme development and you will get this annoying experience. Every time you will have to clear cache when you want to see the changes.
Please are the steps to disable Twig template caching when you are working for Drupal 8 theme development.

But these are the steps not recommended only for Development environment.

Step 1: Copy and rename the sites/example.settings.local.php to be sites/default/settings.local.php

$ cp sites/example.settings.local.php sites/default/settings.local.php

Open settings.php file in sites/default and uncomment these lines:

 if (file_exists(__DIR__ . '/settings.local.php')) {    
   include __DIR__ . '/settings.local.php';  
 }

This will include the local settings file as part of Drupal’s settings file.

Step 2: Open settings.local.php and change the to be TRUE

$config['system.performance']['css']['preprocess'] = FALSE;
$config['system.performance']['js']['preprocess'] = FALSE;

Uncomment these line is settings.local.php to Disable the render cache and Disable Dynamic Page Cache

$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null'; 

If you do not want to install test modules and themes, set following to FALSE

$settings['extension_discovery_scan_tests'] = TRUE;

Open development.services.yml in the sites folder and add the following block (to disable twig cache)

parameters:   
  twig.config:
    debug : true
    auto_reload: true
    cache: false

Leave a Reply

Your email address will not be published. Required fields are marked *