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

frazac_naba created an issue. See original summary.

delta’s picture

If 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

frazac_naba’s picture

Thanks delta, now it works.

how can I know when this incompatibility will be fixed?

many thanks

th_tushar’s picture

Assigned: Unassigned » th_tushar
th_tushar’s picture

Assigned: th_tushar » Unassigned
DamienMcKenna’s picture

Version: 8.x-1.0-beta4 » 8.x-1.x-dev

@frazac_naba: We'll update this issue when the bug is fixed.

DamienMcKenna’s picture

Confirmed the bug, it affects e.g. the default front page.

johnpicozzi’s picture

Looks like I am having this issue with contextual filter title replacement. Anyone working on a patch?

@damienMcKenna - Could this be a problem in D8? I am having a very similar problem where we use a token replacement for the title {{ title }} and it gets replaced correctly on the Drupal Views Preview output. However, on the views page in the tag (browser tab) you see {{ title }} | Site name.

https://www.drupal.org/node/2101301#comment-11741180

Anonymous’s picture

I 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

DamienMcKenna’s picture

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

bmsomega’s picture

Issue summary: View changes

I 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)

/**
 * Implements hook_preprocess_HOOK().
 */
function THEME-NAME_preprocess_html(array &$variables) {
  $path = \Drupal::service('path.current')->getPath();
  $path_args = explode('/', $path);
  $site_name = \Drupal::config('system.site')->get('name');

  if (isset($path_args[3]) && $path_args[3] === 'profile'){
    $variables['head_title']['title'] = $variables['page']['#title'] . ' | ' . $site_name;
  }
}

If I wanted /foo/bar/profile to lead to an actual page, I would just have to add on to the conditional, like so:

if (isset($path_args[3]) && isset($path_args[4]) && $path_args[3] === 'profile'){ 
//the code 
}

Again, this should just be a temporary work-around.

chegor’s picture

There is still no working decision?

DamienMcKenna’s picture

dandaman’s picture

Seems 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!

matsbla’s picture

Title: view's title do not go to title metatag » [current-page:title] doesn't integrare well with views
Project: Metatag » Token
Component: Integration with other module » Code

I 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).

matsbla’s picture

Title: [current-page:title] doesn't integrare well with views » [current-page:title] doesn't integrate well with views
matsbla’s picture

Issue summary: View changes
Shmendrich’s picture

I can confirm this is still an issue with the latest version of drupal and metatag module.

ordermind’s picture

Main issue with patch that fixes this problem can be found here: https://www.drupal.org/project/drupal/issues/2716019

Renrhaf’s picture

Confirming #19

cbrody’s picture

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

hawkeye.twolf’s picture

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

joseph.olstad’s picture

ya patch 19 does NOT resolve the issue for me either

lubwn’s picture

Patch 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!

mandclu’s picture

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

2pha’s picture

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

mkindred’s picture

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