Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
theme system
Priority:
Major
Category:
Bug report
Assigned:
Unassigned
Issue tags:
Reporter:
Created:
6 Nov 2014 at 10:43 UTC
Updated:
22 Nov 2016 at 10:13 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
fabianx commentedGood catch!
Comment #2
fabianx commentedRTBC, makes a lot of sense, we need to be more careful about this now.
Comment #3
jibranIt should be \Drupal::service('path.matcher')->isFrontPage() now.
Comment #4
catchComment #6
catchComment #7
jibranThank you for the fix.
Comment #8
alexpottWe need a change record for this.
Comment #9
almaudoh commentedSmall nit...
Should be
\Drupal::service()right?Comment #10
lauriiiComment #11
davidhernandezChange draft added. Am I correct in thinking that because this is in template_preprocess_page now instead of template_preprocess that the variable isn't accessible everywhere now, by default?
Comment #12
fabianx commentedThat is correct, but needed else every cache item is potentially 'PER_PAGE' suddenly ...
Comment #13
davidhernandezJust modifying some comments.
Otherwise, I'm fine with the change. I played with it some and it seems to work fine for page templates. On the negative side, this reduces the availability of the variable, but the performance improvement outweighs that concern. Any module/theme depending on the variable is easily fixed by checking for the front page directly.
While searching I noticed there are still a number of references to
drupal_is_front_page(). Since that function is deprecated now, shouldn't those be changed? (out of scope for this issue) I didn't see an issue for it.Comment #14
davidhernandezForgot to upload the patches.
Comment #15
lauriiiLooks good to me
Comment #16
alexpottThis issue addresses a major bug and is allowed per https://www.drupal.org/core/beta-changes. Committed 90a26b4 and pushed to 8.0.x. Thanks!
Comment #18
fabianx commentedYes, but as soon as they do that, they will need to ensure that the cache granularity of all objects on that page has the CACHE_PER_PAGE cache context.
Comment #19
davidhernandezFabianx, how do you do that? I want to add that information to the change record, but I'm not finding documentation for it or an implementation to use as an example.
Comment #20
fabianx commentedI honestly don't know how to do that.
I only know that core is setting #pre_render and #cache keys and that that contains cache contexts.
Wim: ^^
Nat: ^^
Comment #22
stefan.kornI am currently trying to figure out a good way to check for front page in a template other than page.html.twig.
Going to preprocess functions for each template that is needed?
I also tried to make a custom Twig Extension that checks with
\Drupal::service('path.matcher')->isFrontPage();for the front page but this is not working, probably due to caching.Is there still an easy way to check for frontpage like in D7?
Would be great if someone can give me a hint.
Comment #23
fabianx commented#22:
So whenever you check the front page you will also need to add a cache context so that the caching layer knows that your block or entity or whatever is encompassed is varied by 'route'.
However per route would be a lot of granularities.
Therefore dawehner proposed that in your contrib twig extension you also register a new cache context:
route.is_front
which just returns two states: TRUE if its the front-page or FALSE otherwise.
Your code in the extension would then need to add the cache context and the easiest is to just render a render array with that, like:
And thats it.
Comment #24
markhalliwell