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.
Some problems with the token [current-page:title]
- it doesn't process the twigs (if you use twig in views titles it will simply output the twig code without processing it first).
- it doesn't respect the title overrides from the contextual filters in views
Comments
Comment #2
delta CreditAttribution: delta commentedIf you disable metatag module, the views title will populate the
<title>
tag normally.This is because of the way metatag override the $variables['head_title'] in hook_preprocess_html().
Related to https://www.drupal.org/node/2563647
Comment #3
frazac_naba CreditAttribution: frazac_naba commentedThanks delta, now it works.
how can I know when this incompatibility will be fixed?
many thanks
Comment #4
th_tushar CreditAttribution: th_tushar commentedComment #5
th_tushar CreditAttribution: th_tushar commentedComment #6
DamienMcKenna@frazac_naba: We'll update this issue when the bug is fixed.
Comment #7
DamienMcKennaConfirmed the bug, it affects e.g. the default front page.
Comment #8
johnpicozziLooks like I am having this issue with contextual filter title replacement. Anyone working on a patch?
https://www.drupal.org/node/2101301#comment-11741180
Comment #9
Anonymous (not verified) CreditAttribution: Anonymous commentedI have the same problem, without metatags the title gets set correctly for views using twig placeholders (like with contextual filters).
Any plan to get this fixed, and are these related?
- https://www.drupal.org/node/2563647
- https://www.drupal.org/node/2101301
Comment #10
DamienMcKenna@Deraynger: Yes, it'll be fixed eventually, how fast depends upon whether someone puts together a patch for this or if I have to do it. The other issues are not directly related to this, one is about adding the meta tag fields to the Views UI, the other is a problem with the D7 module which works quite differently to the D8 module.
Comment #11
bmsomega CreditAttribution: bmsomega at Oomph, Inc. commentedI figured out a temporary work-around for this issue by implementing the
hook_preprocess_html()
function in the .theme file of the theme that I'm using.When you override a View Page title via Contextual Filter, the title is stored in
$variables['page']['#title']
In my case:
- I have a View Page with a path that has 4 arguments (i.e.
/foo/bar/profile/%
)- The Contextual Filter I’m using is the title of a node
- I want the title of my View Page to be:
"node-title" | "site-name"
- My contextual filter is the 4th argument in the path of my View Page
- The path
/foo/bar/profile
does not exist and will direct you to a 404 page (If I wanted this path to lead to an actual path, this process would still work but we would just need to add another conditional inside of the function)If I wanted
/foo/bar/profile
to lead to an actual page, I would just have to add on to the conditional, like so:Again, this should just be a temporary work-around.
Comment #12
chegor CreditAttribution: chegor as a volunteer commentedThere is still no working decision?
Comment #13
DamienMcKennaComment #14
dandaman CreditAttribution: dandaman commentedSeems to me this is still an issue. On my site, the page title is just the View Title even though the title in the page content is overridden with the value set in the "Contextual Filters" section of the View (the "Override Title" section of the filter). Thanks for your work, Damien and all!
Comment #15
matsbla CreditAttribution: matsbla at Globalbility commentedI think this is an issue with the [current-page:title] token, from token module, not the metatag module itself.
The problem is that the token [current-page:title] doesn't respect the title overrides from the contextual filters, and also that it doesn't process the twigs (if you use twig it will simply output the twig code without processing it first).
Comment #16
matsbla CreditAttribution: matsbla at Globalbility commentedComment #17
matsbla CreditAttribution: matsbla at Globalbility commentedComment #18
Shmendrich CreditAttribution: Shmendrich commentedI can confirm this is still an issue with the latest version of drupal and metatag module.
Comment #19
ordermind CreditAttribution: ordermind commentedMain issue with patch that fixes this problem can be found here: https://www.drupal.org/project/drupal/issues/2716019
Comment #20
RenrhafConfirming #19
Comment #21
cbrody CreditAttribution: cbrody as a volunteer and commented#19 does not resolve the issue for me. Using a taxonomy term argument in the page title
{{ arguments.term_node_taxonomy_name_depth }}
results in the twig not being processed when page title is re-written via the[current-page:title]
token in the metatag module.Comment #22
hawkeye.twolfSame results as @cbrody: The core patch linked in #19 does not fix the issue for me. I ended up removing the default page title pattern from Metatag configuration, letting it fallback to the default "[current-page:title] | [site:name]" set by core. With this change, I could leave Metatag installed and controlling the other metatags but not have it affect my page title overrides from Views contextual arguments.
Comment #23
joseph.olstadya patch 19 does NOT resolve the issue for me either
Comment #24
lubwn CreditAttribution: lubwn commentedPatch 19 solves an issue for me. I am generating titles with tokens from contexual filters. Before they were just twigs, now they works nicely. Thanks!
Comment #25
mandclu CreditAttribution: mandclu at Northern Commerce commentedThe patch from #19 didn't seem to improve anything for me. Removing the global Page Title pattern did improve the title tag for me, but I am still having an issue with breadcrumbs.
Comment #26
2phaI came across this problem too when using the metatag module on a views page.
I am altering a view page title in a HOOK_views_post_render with $view->setTitle();
Without the metatag module the page title and tag work as expected (both what I set with $view->setTitle()).
With metatag module on and the "title" meta set to "[current-page:title] | [site:name]", the tag does not have what I would expect for [current-page:title] , it is blank.
Weirdly, the first time I load the page after a cache clear, it seems to work ok, subsequent page loads do not (so something to do with caching?).
#19 was no help in my situation.
EDIT:
It seems line 762 of token.token.inc
$title = \Drupal::service('title_resolver')->getTitle($request, $route);
gets null on views pages, at least in my case
Turns out I could work around my situation by adding [view:title] as the title metatag on the view itself.
Comment #27
mkindred CreditAttribution: mkindred commentedI ran into this problem with a view that uses a taxonomy contextual filter
{{ arguments.name }}
as a title. On the suggestion from @2pha, I enabled Metatag Views to override, using[view:title] | [site:name]
in Meta tags: Page Title within the view.