Untitled
function YOURTHEME_preprocess_page(array &$variables) { if (\Drupal::routeMatch()->getRouteName() == 'entity.node.canonical') { $node = \Drupal::routeMatch()->getParameter('node'); if ($node instanceof \Drupal\node\NodeInterface && $node->bundle() == 'page') { $variables['hero_image'] = ''; if ($node->hasField('field_hero_image') && !$node->get('field_hero_image')->isEmpty()) { $variables['hero_image'] = \Drupal::service('renderer')->render($node->get('field_hero_image')->view('hero_image')); } } } }
Leave a Comment