Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Changing follow vars, you will not see it take effect immediately because the settings was cached. We need to tell themers to clear the caches after the setting changes.
$settings['twig_debug'] = TRUE;
$settings['twig_auto_reload'] = TRUE;
$settings['twig_cache'] = FALSE;
Comment | File | Size | Author |
---|---|---|---|
#34 | interdiff.txt | 1.18 KB | Outi |
#34 | ImproveTwigVarsDocsInSettingsDotPHP-34.patch | 2.39 KB | Outi |
#30 | twig_debug-cache_clear-2056879-30-do-not-test.patch | 1.18 KB | star-szr |
#28 | interdiff.txt | 556 bytes | Outi |
#28 | ImproveTwigVarsDocsInSettingsDotPHP-6.patch | 1.23 KB | Outi |
Comments
Comment #1
jhodgdonIt is certainly true for more than just Twig settings... Do we make similar "clear the cache" statements for other settings?
Comment #2
droplet CreditAttribution: droplet commentedAFAIK, We do not need to clear cache for other settings.
Comment #3
jhodgdonOK then, just needs a patch.
Comment #4
martin107 CreditAttribution: martin107 commentedSample Patch as requested
Comment #5
martin107 CreditAttribution: martin107 commentedComment #6
martin107 CreditAttribution: martin107 commentedComment #7
jhodgdonThanks! Can we get a bit of a grammar update?
Either follow Note with a : or the word "that". Thanks!
Comment #8
martin107 CreditAttribution: martin107 commentedAdded colon.
Comment #9
martin107 CreditAttribution: martin107 commentedComment #10
jhodgdonThanks! Unfortunately, that makes the lines longer than 80 characters, so they need to be wrapped.
Comment #11
martin107 CreditAttribution: martin107 commentedCorrected wrapping and trailing whitespace issue.
Comment #12
martin107 CreditAttribution: martin107 commentedComment #13
jhodgdonThe documentation looks good to me.
I am still not certain that it is accurate, so I am not setting to RTBC until someone can verify that:
- If you change any of these settings and do not clear the cache, they do not take effect.
- If you then clear the cache, the setting does take effect.
This will probably require manual testing and each setting should be tested individually.
Comment #14
ioskevich CreditAttribution: ioskevich commentedComment #15
ioskevich CreditAttribution: ioskevich commentedAdding CodeSprintCIS tag.
Comment #16
ioskevich CreditAttribution: ioskevich commentedPrecondition:
Clean Drupal 8 install. Logged in as UID 1, Drupal page cache disabled.
Tested markup changes on home page, modifications were done to /core/themes/bartik/templates/page.html.twig
1. $settings['twig_debug']
$settings['twig_auto_reload'] and $settings['twig_cache'] set to defaults (commented out).
Changing from FALSE to TRUE and vice-versa triggers output of TWIG debug (HTML comments injected into resulting page markup) immediately on page reload, no Drupal cache flush required.
Summary: cache flush IS NOT required to make this setting to work.
2. $settings['twig_auto_reload']
Tested with $settings['twig_debug'] set to FALSE, $settings['twig_cache'] = TRUE;
2.1 $settings['twig_auto_reload'] set to FALSE
2.2 $settings['twig_auto_reload'] set to TRUE
Summary: cache flush IS required to make this setting changes to apply.
3. $settings['twig_cache']
$settings['twig_debug'], $settings['twig_auto_reload'] set to default values (commented out).
Monitoring twig cache directory: /sites/default/files/php
3.1 $settings['twig_cache'] set to TRUE
3.2 $settings['twig_cache'] set to FALSE
Summary: cache flush IS required to make this setting changes to apply.
Comment #17
martin107 CreditAttribution: martin107 commentedThanks Ioskevich, here is a patch that reflects your advice.
Comment #18
droplet CreditAttribution: droplet commentedThis one included the DUMP function, can you re-test again? Thanks.
Comment #19
ioskevich CreditAttribution: ioskevich commentedComment #20
ioskevich CreditAttribution: ioskevich commentedChanging value of $settings['twig_debug']:
Debug markup is added/removed WITHOUT clearing cache.
To use dump() function, cache clear IS REQUIRED.
Might make sense to change help text for $settings['twig_debug'] in settings.php to reflect this?
Comment #21
ioskevich CreditAttribution: ioskevich commentedLost original tags somehow - re-adding.
Comment #22
jhodgdonI think we can get rid of the 'needs manual testing' tag at this point, because (THANK YOU!) ioskevitch tested it. :)
Comment #23
star-szrJust came across this so tagging as 'Twig' to hopefully get some eyes on it :)
Comment #24
star-szrI know the documentation tag is redundant but I'm just adding it so that this issue shows up on http://drupaltwig.org/issues/documentation which I just set up, hope that doesn't mess anyone up.
Comment #25
Outi CreditAttribution: Outi commentedI tested using the dump() function with the $settings['twig_debug'] set to TRUE, and the cache clear is indeed required as ioskevich pointed out in the comment #20. I changed the twig_debug help text to note this.
Comment #26
Outi CreditAttribution: Outi commentedComment #28
Outi CreditAttribution: Outi commentedThe last patch wasn't the right one, this one includes the changes I wanted to make.
Comment #29
star-szrThanks @Outi! It gets a bit more complicated because twig_auto_reload depends on twig_debug in a way: http://twig.sensiolabs.org/doc/api.html#environment-options
I would suggest we say that dump() and automatic reloading need a cache clear to take effect, and if we want to be really explicit we can say debug markup will show up immediately. Maybe we can split up this list into two sections and state that the second part (dump and auto_reload) need a cache clear to take effect?
Also for what it's worth it should be possible to make the debug markup only show up after cache clear. My first impression is that seems a bit undesirable but it would make things consistent and easier to document :)
Comment #30
star-szrThis is the basic idea of how the last paragraph of my last comment would work - need to determine if this would still be testable but I'd like some feedback as to what folks think about this. To me it seems good that the debug markup would be consistent with dump() and auto reload, otherwise you can get into a state where things seem "half working".
Steps to test:
Comment #31
Outi CreditAttribution: Outi commentedCottser, I tested your patch and it might indeed be a good idea to require the cache clear everywhere. In that case I'll change the help text.
By the way, it seems to me that this point at the $settings['twig_debug'] help text is duplicating what follows in the help text of $settings['twig_auto_reload']:
Help text of $settings['twig_auto_reload']:
And should the default value mentioned on the help text of $settings['twig_auto_reload'] be FALSE (as elsewhere) and not NULL ?
* Not recommended in production environments (Default: NULL).
Comment #32
star-szrThanks @Outi! I think if we combine the patches from #25 and #30 then we've covered our bases pretty well here (but I'm happy to be proven wrong!). Moving to the theme system component (we still have the 'documentation' tag) to account for the functional change.
The duplication in twig_debug help text is intentional because there is a common misunderstanding that twig_auto_reload is needed to allow for automatic template recompilation. The default of NULL is true because if twig_auto_reload is left NULL it inherits the value of twig_debug.
The short version is: as a themer all you really need is
twig_debug = TRUE
99% of the time.You can see where the Twig service is set up in \Drupal\Core\CoreServiceProvider::registerTwig():
Comment #33
star-szrOh, and also expect tests to fail with the change made in twig.engine if you post a combined patch, those will need some reworking.
Comment #34
Outi CreditAttribution: Outi commentedHere is a patch that combines the patches of the comment #25 and the comment #30. The interdiff file is between the patch of the comment #25 and this new patch.
Comment #35
star-szrI'm slightly surprised that tests pass but great :D Thanks @Outi!
Comment #36
Fabianx CreditAttribution: Fabianx commentedRTBC, nice work. Makes sense and if anyone wants to have things take immediate effect, they would need to disable the container caching by using e.g. a read-only filesystem class for the PHPStorage (not that anyone would want to).
Also reduces dependencies and keeps things with in the service.
Full win!
Comment #37
webchickCool, seems like this will save some poor themers some face-desking.
Committed and pushed to 8.x. Thanks!