Page title with substitution on views page I have a view page that requires a dynamic page title. It is a simple substitution of the label field.

If I use {{ label }} it works fine for the title displayed on the page, but it doesn't substitute the label for the actual page title (in meta)

I was able to fix this by using hook_views_post_render using the following code

// Set the route title.
$route = \Drupal::routeMatch()-&gt;getCurrentRouteMatch()-&gt;getRouteObject();
$route-&gt;setDefault('_title', $title);

$view-&gt;setTitle($title);


However, the title only works if the page is not cached. For the cached pages, the page title is missing. This feels like a bug in drupal, but I am hoping that there is a simple way to get this done.
You can't change the route object in a hook. Use a RouteSubscriber to add a dynamic _title_callback to the view route.

Otherwise setTitle() should work. The bug you've described is not a bug. It's about caching in general. When you add dynamic data you also have to add the cache metadata, which defines what kind of dynamic data this is.

For example if the dynamic title depends on the node 123:

$output['#cache']['tags'][] = 'node:123';