Drupal 8 get page title from route and set this to page_title block
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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