0
function THEMENAME_preprocess_views_view(&$variables){
        $view = $variables['view'];
      if($view->name == "YOUR_VIEW_NAME" && $view->current_display == "MACHINE_NAME_OF_VIEW"){
        $variables['attributes']['class'][] = 'page-'.$view->name;
    }

For some reason this does not work. Any ideas?

0

this one worked:

function THEMENAME_preprocess_html(&$variables) { 
  //view name as body class
  $variables['view_title'] = '';
  $route = \Drupal::routeMatch()->getRouteObject();
  if ($route) {
    $view_title = $route->getDefault('_title');
    $variables['attributes']['class'][] = 'view-' . $view_title;
  }
}
  • What if the view title has an empty space? ex: Hello World – No Sssweat May 22 at 22:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.