Drupal 7 Theming: Adding a Views Name as a Body Class

There's a neat little Drupal 7 (Views 3.x) API function called views_get_page_view() that comes in handy for querying the name of the view for Views Pages. Note, for this to work, it must be a "page display" in the view with a path set, not a block, or pane, etc.

/**
 * Implements template_preprocess_html().
 *
 * Misc page preprocess functions.
 */
function mytheme_preprocess_html(&$vars) {

// Query the view and add a class.
$view = views_get_page_view();
 if (
  isset($view) &&
  $view->name == 'actions' &&
  $view->current_display == "page"
) {
    $vars['classes_array'][] = 'views-actions-page';
  }
}

This ends up rendering as:

<body class="html not-front logged-in no-sidebars page-actions section-actions page-views flush-header views-actions-page">

Resources