Early Bird Registration for DrupalCon Portland 2024 is open! Register by 23:59 PST on 31 March 2024, to get $100 off your ticket.
By finngruwier on
I'm trying to dive into Drupal 8 Twig templating. My problem is that I need to clear Drupals caches every time I have made a change, even after disabling caches with Drupal Console ('drupal site:mode dev').
Comments
Settings for twig are done in
If drupal console isn't working for twig settings you can manually do them in services.yml in the default directory of the sites directory under the twig.config group. To enable what is normally desired for development work the settings are typically set as
twig.config:
debug:true
auto_reload: true
cache: false
There are comments in the file which explain what each setting accomplishes. Always rebuild/clear cache after changing settings.
I just checked what
I just checked what combination of options Drupal Console actually sets in services.yml. It turns out that it sets cache to true! After setting cache to false (and clearing caches) it actually works.
I just assumed that 'drupal site:mode dev' would set cache to false which would have been the obvious choice. Thanks for helping with clearing this out.
Not working for me
I have followed above steps
- twig.config:
debug:true
auto_reload: true
cache: false
and Making JS, CSS change too in performance tab.
Still I am not able to disable cache for my Twig template
The settings proposed by
The settings proposed by slewazimuth may not be enough. Full instructions of how to disable cache for development can be found at Disable Drupal 8 caching during development
-------------------------------------------------
take a look -> www.altrugon.com
Issue is Resolved for me
I have added below line in my code and it worked for me.
\Drupal::service('page_cache_kill_switch')->trigger();
'#cache' => ['max-age' => 0,],
It works for me
thank you
Thanks
The instructions on Disable Drupal 8 caching during development did the trick.
Worked like charm!! https:/
Worked like charm!! https://www.drupal.org/node/2598914
As from Drupal 8.4
If you are using Drupal verison greater than or equal to 8.4 then add the following lines to your setting.local.php
This Worked For Me !!
1.Copy and rename the file from sites/example.settings.local.php to sites/default/settings.local.php
2.Open settings.php file in sites/default and uncomment these lines:
if (file_exists($app_root . '/' . $site_path . '/settings.local.php')) {
include $app_root . '/' . $site_path . '/settings.local.php';
}
3.Uncomment these lines in settings.local.php
$settings['cache']['bins']['render'] = 'cache.backend.null';
$settings['cache']['bins']['dynamic_page_cache'] = 'cache.backend.null';
4. Open development.services.yml in the sites folder and add the following code
parameters:
twig.config:
debug: true
auto_reload: true
cache: false
4. Rebuild the cache and your good to go
Worked like charm!! Thanks
Worked like charm!! Thanks
Watch out for leading whitespaces
Please remember that leading whitespaces are very important im
.yml
files. So the exampleparameters:
-section from rahul_k'sdevelopment.services.yml
file above should look likeDrupal 9
I tried to disable the drupal and twig caches on Drupal 9 following your suggestions but it seems to not work, every time I change something to a twig template I must manually clear the cache.
Tried also to disable OPCache from PHP server but nothing changes.
Do you have any suggestions or faster methods to disable caches during development?
The last step for me was
The last step for me was viewing changes while logged in. I am used to testing site changes in a separate browser as an anonymous user, but per the instructions (https://www.drupal.org/node/2598914):
"IMPORTANT NOTE: Accessing the site as an anonymous user still makes use of caching even when local development settings have been enabled. You must be logged in to view your site with caches disabled."