1

I'm theming a Drupal 7 site and I'd like to add a class to all the blocks in a given region using preprocess_block().

I think this should work, but it doesn't seem to:

function MYTHEME_preprocess_block(&$variables) {
        // Other stuff in this function
        $variables['title_attributes_array']['class'][] = 'title';
        $variables['classes_array'][]='clearfix';

        // Now I want to add a 'col-md-4' class to all the blocks in the 'bottom-content' region
        if($variables['block']->region == 'bottom-content') {
                $variables['classes_array'][]='col-md-4';
        }
}

Any ideas why this isn't working?

1
  • Are you sure your block region name is correct?
    – Manikandan
    Commented Jan 20, 2016 at 8:02

1 Answer 1

0

As manikandan kannan is saying, you probably have the name of the region wrong. It probably is: 'content_bottom'

So your if-statement would become:

if($variables['block']->region == 'content_bottom') { ...
1
  • The word order was right, but it was an underscore instead of a minus sign. Changing it to 'bottom_content' solved the problem. I should have looked in my MYTHEME.info file sooner - it lists all the regions appropriately. Commented Jan 21, 2016 at 0:17

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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