Untitled

 avatar
unknown
plain_text
a year ago
563 B
5
Indexable
<?php

/**
 * Implements hook_preprocess_HOOK() for html.html.twig.
 */
function custom_body_class_preprocess_html(array &$variables) {
  // Get the current path alias.
  $current_path = \Drupal::service('path_alias.manager')->getAliasByPath(\Drupal::service('path.current')->getPath());

  // Define the path alias where you want to add the class.
  $target_alias = '/your/target/path';

  // Add the class if the current path matches the target alias.
  if ($current_path === $target_alias) {
    $variables['attributes']['class'][] = 'your-custom-class';
  }
}
Editor is loading...
Leave a Comment