Disable twig cache for development

Since twig templates are cached, you have to clear the cache each time you make a change in order to see it. For developing themes and modules, you want to disable the cache. The Drupal docs has some info on this, but I think it's not quite as straightforward as it could be:

 

First, let's copy /sites/development.services.yml to /sites/default/services.yml - this is assuming it's your only services file, otherwise merge the settings in.

Your parameters should include:

parameters:

  twig.config:

   debug: true

 

Buried on the second page is info on how to use cache.backend.null (defined in development.services.yml).

Add this to your settings.php.

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

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

 

You're done! Just clear the cache and now any template changes should be reflected when you refresh the page. You will still need to clear the cache if new templates or hooks are created.