Enable Views contextual filter page <title> overriding in Drupal 8

Phil Wolstenholme
Jan 24, 2017 · 1 min read

Views in Drupal doesn’t seem to support a contextual filter value overriding the <title> of a view being displayed as a page. The heading on the page changes, but the title in the <head> of the document isn’t altered.

Here’s one way how to have a custom module take the view title (with the contextual filter override correctly inserted) and apply it to the route (page) title:

(Note that that is a very targeted hook_views_post_render function in a specific custom module and so it bails out early if the ID and display don’t match what we’re looking for. In a more general module you’d want to remove the early return call and instead wrap lines 13–15 in another if statement)

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store