Untitled

mail@pastecode.io avatar
unknown
plain_text
25 days ago
563 B
2
Indexable
Never
<?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';
  }
}
Leave a Comment