Last Updated: October 22, 2018
·
66
· jasloe

Add class to body based on path

<?php

/**
* @file
* Functions to support theming in the custom theme.
*/

use Drupal\Core\Url;

/**
* Implements templatepreprocesshtml().
* @param array $variables
*/
function custompreprocesshtml(&$variables) {
$currentpath = \Drupal::service('path.current')->getPath();
$path
alias = \Drupal::service('path.aliasmanager')->getAliasByPath($currentpath);
$pathalias = ltrim($pathalias, '/');
$variables['attributes']['class'][] = 'path-' . \Drupal\Component\Utility\Html::cleanCssIdentifier($path_alias);
}
//kint($variables);
}