Skip to content

Instantly share code, notes, and snippets.

@vkechagias
Created October 21, 2019 12:32
Embed
What would you like to do?
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