6

I've followed these instructions to disable Twig caching:

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

  3. Open settings.local.php and change the to be TRUE

    $config['system.performance']['css']['preprocess'] = FALSE;
    $config['system.performance']['js']['preprocess'] = FALSE;
    
  4. 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;
    
  5. 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
    

I double and triple checked, all changes have been correctly applied per the above. But nothing has changed, I still need to rebuild cache every time I make a change to a template file for it to show up in the front end.

So, what are the correct steps to disable Twig caching on a stock installation of Drupal 8.0.1, with no contrib or custom modules installed?

closed as off-topic by Clive Dec 22 '15 at 15:08

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question was caused by a problem that can no longer be reproduced, was solved by a cache clear, or was a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers." – Clive
If this question can be reworded to fit the rules in the help center, please edit the question.

  • Have you checked performance settings? There was caching enabled on my installation per default... – Volker Dec 17 '15 at 12:09
  • Thanks @Volker, that's the first place I checked - aggregation was turned on but caching was and is turned off (agg is now off too and caches have been rebuilt) – Clive Dec 17 '15 at 12:18
  • 1
    I am not 100% sure it will help in this situation, but also make sure your local APC or OpCache is disabled, or set to rescan every time. – mpdonadio Dec 17 '15 at 13:49
  • Weird, this should definitely work. First thing is to figure out which cache it is exactly. You mentioned template change, if you change something in a hook_*_view() or other place in PHP that's just render cached, does that get updated? Try dumping the actual settings in your compiled container with drush ev "var_dump(\Drupal::getContainer()->getParameter('twig.config'))". Make sure that the order of your services.yml includes is correct. – Berdir Dec 17 '15 at 21:17
  • @Berdir Turned out to be something waaaay down the pipeline that was causing the problem, the docs are spot on – Clive Dec 22 '15 at 15:08
0

Auto reload should be null, then the twig compilation is switched when you enable debug.

auto_reload: null

The quickest way to enable twig debugging is to copy default.services.yml to services.yml and set debug: true and cache: false

You can check this, if you look at the precomplied twigs, when you turn on twig debugging, this directory should no longer be present:

/sites/default/files/php/twig
  • I'd rather keep my development settings in the recommended place, development.services.yml, which is included by my sites/default/local.settings.php (which is in turn included in the normal settings.php). Are you saying that's not possible and I should use the production settings file instead for this? Changing auto_reload didn't make a difference unfortunately – Clive Dec 17 '15 at 13:00
  • Just tried copying default.services.tml to services.yml, made the changes you suggested, rebuilt cache - no difference, still have to rebuild cache every time I make a change to a twig template for it to show up. Thanks anyway – Clive Dec 17 '15 at 13:04
  • I've done this dozens of time, switching twig debug on and off, never had any problems, this is very strange. Do you see the debug comments, when viewing the source in the browser? (and see the answer for additional information) – 4k4 Dec 17 '15 at 13:22
  • It is strange @4k4 :) I've done this before and not had a problem too, not sure why it's suddenly started on this site. Just in a meeting but will try your other suggestions a bit later – Clive Dec 17 '15 at 13:37
  • The problem turned out to be a combination of things on my local machine that were hiding the real issue. Sorry for wasting your time, thanks again for the response – Clive Dec 22 '15 at 15:07
0
  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
    
  2. 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.

  3. Open settings.local.php and change the to be TRUE

    $config['system.performance']['css']['preprocess'] = FALSE;
    $config['system.performance']['js']['preprocess'] = FALSE;
    
  4. 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;
    
  5. 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
    

After completing these steps add this two lines in your settings.php and clear the cache.

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

$settings['container_yamls'][] = DRUPAL_ROOT . '/sites/development.services.yml';

It worked for my colleague. Hope it works for you.

  • Thanks, I tried that too but no difference - still need to clear cache every time I change anything in page.html.twig – Clive Dec 22 '15 at 14:36
  • The problem turned out to be a combination of things on my local machine that were hiding the real issue. Sorry for wasting your time, thanks again for the response – Clive Dec 22 '15 at 15:07

Not the answer you're looking for? Browse other questions tagged or ask your own question.