Created
February 25, 2017 06:57
-
-
Save DejanBelic/8889c60930a99d85935c6f8b535fa6d6 to your computer and use it in GitHub Desktop.
Add node title as body class in drupal 8.
This file contains hidden or 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_html(&$variables) { | |
// Add node title as body class. | |
if ($node = \Drupal::routeMatch()->getParameter('node')) { | |
$node = $node->getTranslation('en'); | |
$title = $node->label(); | |
$title = str_replace(' ', '-', $title); | |
$title = str_replace('_', '-', $title); | |
$variables['title_en'] = strtolower($title); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Why not send it straight to the body class, replace last line with:
$variables['attributes']['class'][] = strtolower($title);