2

I need to know how many blocks in the region! is there any short way to do that ? if more than one block in the region than I want to add custom class to region.

1 Answer 1

4

I think your best bet would be to use hook_preprocess_region() in a module or theme:

function MYTHEME_preprocess_region(&$vars) {
  // Make sure it's the right region
  if ($vars['region'] == 'sidebar_first') {
    // Get the count of blocks
    $count = count(element_children($vars['elements']));

    // Add the class if necessary
    if ($count > 1) {
      $vars['classes_array'][] = 'some-class';
    }
  }
}
0

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.