I'm wanting to apply some specific CSS on the condition that a block region is empty. How do I make this check?


An update on this. I used the solution at https://drupal.stackexchange.com/a/73685/56728 as follows

  module_load_include('inc', 'block', 'block.admin');
  global $theme_key;
  $blocks = block_admin_display_prepare_blocks($theme_key);
  //test for a named block's (here the help block) visibility
  foreach($blocks as $block){
    if($block['delta'] == 'help' && $block['region'] != -1){
      sdpm($block['delta']. " is visible!");

This detects whether the block is visible or not, but does not quite do what I'm after which is to test for the visibility of a given block on the current "page" for the current user. That to me sounds like what block_list() does, but I'm stumped by block_list() as I mentioned above. My "solution" also very likely not the most elegant way of doing things so any help from experts out there would be greatly appreciated. Nat

| improve this answer | |

If you're in you're in a page template you can check your $page region variable for an empty an array of block objects.

if (empty($page['my_region']) { /*DO STUFF*/ }

If you're in another context you can use the block_list function to determine this.

$blocks = block_list('my_region');
if (empty($blocks)) { /*DO STUFF*/ }
| improve this answer | |

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.