When I created a Block using views, this is the HTML that it generates

<div class="block block-views" id="block-views-latest-articles-block"
      <h2>Latest Articles</h2>
        <div class="content">
          <div class="view view-latest-articles view-id-latest_articles view-display-id-block grid-5 omega view-dom-id-4">
            <div class="view-content">
                      // Block Content comes here
            </div>
          </div>   
        </div>
</div>

I want to somehow add the CSS class that I mentioned in the view to the outer most div instead of the inner div. Is that possible?

Comments

dawehner’s picture

Status: Active » Fixed

You can use hook_preprocess_block in your theme to add something to $vars['classes_array'].

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

doublejosh’s picture

Here's how to add the view name among the classes with a Drupal 6 theme layer solution...

function MYTHEME_preprocess_block(&$vars, $hook) {
  // Get the view name into the block classes.
  if ($vars['block']->module == 'views') {
    $delta = explode('-', $vars['block']->bid); // EX: views-articles-block_1, views--exp-articles-block_1
    $vars['classes_array'][] = ($delta[2] == 'exp') ? 'view-'. $delta[3] : 'view-'.$delta[1];
  }
}

You can also just add a class via the views UI.

marvix’s picture

You can also just add a class via the views UI.

Would please show me from where, the only option is adding a class to the internal div, not to the main block div.

merlinofchaos’s picture

Views doesn't control or render the main block div, and it can't add classes there. It's simply not possible for the UI to add a class there, which is why the preprocess method shown here is necessary.

merlinofchaos’s picture

Issue summary: View changes

Fixed Error