Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
492 B
2
Indexable
Never
/**
 * Implements hook_preprocess_HOOK() for node.html.twig.
 */
function your_theme_name_preprocess_node(array &$variables) {
  // Get the current path alias.
  $alias = \Drupal::service('path_alias.manager')->getAliasByPath('/node/' . $variables['node']->id());

  // Clean the alias to be suitable as a CSS class.
  $alias_class = str_replace('/', '-', trim($alias, '/'));

  // Add the alias class to the node attributes.
  $variables['attributes']['class'][] = 'alias-' . $alias_class;
}
Leave a Comment