Skip to content

Instantly share code, notes, and snippets.

@langelhc
Created April 24, 2020 17:35
Show Gist options
  • Save langelhc/2a528e210e6bed6d0a30f45dfab7607a to your computer and use it in GitHub Desktop.
Save langelhc/2a528e210e6bed6d0a30f45dfab7607a to your computer and use it in GitHub Desktop.
Add term name to body class
function THEME_preprocess_html(&$variables) {
if ($variables['node_type'] == 'page') {
$node_id = \Drupal::routeMatch()->getRawParameter('node');
$node = Node::load($node_id);
if ($term = $node->get('field_page_type')->entity) {
$term_name = $term->get('name')->getString();
switch ($term_name) {
case 'My term':
$variables['page_type'] = $term_name;
break;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment