0

Looking for a way to clear all unnecessary in terms of semantic classes from top-level div for a view:

<div class="view view-comments-count view-id-comments_count view-display-id-entity_view_2 view-dom-id-f2370f55bf76844fef6e17764e8a5058">
      <div class="view-content">
        ROWS
    </div>
</div>

want to become:

<div class="view">
      <div class="view-content">
        ROWS
    </div>
</div>

I have tried Semantic Views and Fences but they all deal only with view content (field or rows) but not with the top-level div config.

I know that some bits can be changed with views-view.tpl.php however you can only clear all classes from it but I want to use css class from Views configuration.

2

You can use template_preprocess_views_view function and remove needles classes from $vars['classes_array'] array.

function mymodule_preprocess_views_view(&$vars) {
  if ($vars['view']->name == 'my_view') {
    $vars['classes_array'] = array('view', $vars['css_class']);
  }
}
  • In this case I wouldn't be able to set the class in a views setting (called CSS class). – Valera Tumash Jul 21 '15 at 5:29
  • You can add this class in array in template_preprocess_views_view – Andrew Jul 21 '15 at 5:59
  • How do I find this class in an array? I want the class to be set from Views UI. – Valera Tumash Jul 21 '15 at 6:15
  • $css_class = $view->display_handler->get_option('css_class'); if (!empty($css_class)) { $vars['css_class'] = preg_replace('/[^a-zA-Z0-9- ]/', '-', $css_class); $vars['classes_array'][] = $vars['css_class']; } – Andrew Jul 21 '15 at 6:20
  • Sorry, I didn't get where I need to put this code. $view is undefined in the module. – Valera Tumash Jul 21 '15 at 6: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.