4

I am using a menu_block block that displays sub-menus depending on what page the user is. on some pages, there are no sub-menus, so my menu-block is automatically hidden by drupal. how do i force drupal to display my block even if it is empty?

thanks.

  • 4
    Why would you want to display a block that contains nothing? If you have side-effects from this block showing, then move those instead, so a relevant template for example. – Letharion Apr 11 '12 at 10:29
  • Hi, thanks. it's a client request. they want to display at least the block title. – Bibokid Apr 12 '12 at 2:35
  • 5
    Try adding   in content if empty, it should come up – GoodSp33d Apr 12 '12 at 9:00
1

I agree with '2-Stroker'. Do this:

function HOOK_block_view_alter(&$data, $block) {
  if ($block->module == 'menu_block' && $block->delta == 'DELTA_OF_THE_BLOCK') {
    $data = array('subject' => 'TITLE OF BLOCK', 'content' => ' ');
  }
}
|improve this answer|||||
0

I don't know of a way to explicitly force a block (title) to render if the block content is empty.

I would have hidden the block title from the block itself, and the put the title in an appropriate template.

|improve this answer|||||
0

One way would be to actually put something in it... but hide it via CSS. I actually had to do that to accomplish a quick hack to lobotomize some bad legacy code.

|improve this answer|||||
0

You could create a second block that simply contained the title and then toggle the block visibility based on whether or not the other block exists. You can achieve this by either turning on the PHP filter module and writing some custom PHP to detect if the first block is present or not, or you can write a custom module to do this if you don't want PHP filter on as noted here: Is there a way to set block visibility programmatically without using the PHP Filter module?

|improve this answer|||||
0

I found a work around for my project was to simply make a switch case for the block creation, either "Create Block with content" or "Create block with message"

Example:

function ms_server_status_block_view($block_name = '') {
  $block = array( 'subject' => t('TITLE'), 'content' => $content, );
  //OR THIS: $block = array( 'subject' => t('TITLE'), 'content' => 'DEFAULT COMMENT', );
}
|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.