How to add the view name as body class function THEMENAME_preprocess_views_view(&amp;$variables){
        $view = $variables['view'];
      if($view-&gt;name == "YOUR_VIEW_NAME" &amp;&amp; $view-&gt;current_display == "MACHINE_NAME_OF_VIEW"){
        $variables['attributes']['class'][] = 'page-'.$view-&gt;name;
    }


For some reason this does not work. Any ideas?
this one worked:

function THEMENAME_preprocess_html(&amp;$variables) { 
  //view name as body class
  $variables['view_title'] = '';
  $route = \Drupal::routeMatch()-&gt;getRouteObject();
  if ($route) {
    $view_title = $route-&gt;getDefault('_title');
    $variables['attributes']['class'][] = 'view-' . $view_title;
  }
}