Created
April 24, 2020 17:35
-
-
Save langelhc/2a528e210e6bed6d0a30f45dfab7607a to your computer and use it in GitHub Desktop.
Add term name to body class
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 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