My page content type contains the field field_subheading. How can I make this field available in the template page-title.html.twig?
Below code doesn't work, probably because $variables['node'] isn't set. Also, I don't know, if it's correkt to retrieve the field value by $variables['node']->field_subheading->value;
. Thanks!
/**
* Implements hook_theme_preprocess_page_title().
*/
function mytheme_preprocess_page_title(&$variables) {
$node = \Drupal::request()->attributes->get('node');
if ($node && $node->bundle() == 'page') {
if (isset($variables['node'])) {
$variables['subheading'] = $variables['node']->field_subheading->value;
}
}
}
kk