Skip to content

Instantly share code, notes, and snippets.

@vkechagias
Created October 21, 2019 12:32
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vkechagias/ae2792fa9f68593cbebaf7516fef83bb to your computer and use it in GitHub Desktop.
Save vkechagias/ae2792fa9f68593cbebaf7516fef83bb to your computer and use it in GitHub Desktop.
Drupal 8 get page title from route and set this to page_title block
function HOOK_preprocess_block__page_title_block(&$variables) {
$request = \Drupal::request();
$route_match = \Drupal::routeMatch();
$page_title = \Drupal::service('title_resolver')->getTitle($request, $route_match->getRouteObject());
if (!empty($page_title) && empty($variables['content']['#title'])) {
$variables['content']['#title'] = $page_title;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment