0

I have two block (like Block1 and Block2) and I have to display one block among two. Condition is Block1 will be display into the whole site if Block2 is not present there. Block2 will be displayed into specific pages which is controlled dynamically, i.e. when user create content in future they can control the Block2 display. So I need to display Block1 where Block2 is not present.

I am using Durpal 7.

Note: I have tried with default block visibility but this is not worked for me either.

1
  • Not a good solution but you should try with tpl files and call the block1 in the condition of the pages. – j2r Mar 15 '12 at 6:58
1

This sounds like you're going to need to use something like Context to toggle the display of each of the two blocks depending on the context of the page.

See this tutorial for more info on how that works.

0

Assuming you want these blocks displayed in the same place on your page and you are creating these blocks yourself in a module, eg, they aren't somehow standard blocks from one or more other modules, you could do all of this in the display logic of one block:

if ( the user is on a path/page that the content of block2 should be displayed ) &&
   ( the user has created whatever content you mentioned ) {
      $content=what should be in block 2;
} else { 
  $content=what should be in block 1;
}

That's pseudo code obviously as I don't know what paths you need to check against (eg, $_GET['q']) for block 2, nor do I know what you need to check against viz the future content you mentioned that will allow block 2 to be finally displayed, let alone what html (or renderable array that will eventually be rendered) you want in either of the blocks.

Regardless, all of the above would be put in the block_view() hook of your module along with a corresponding block_info() hook.

Now, if they are somehow standard blocks from another module, you could hack around with $block = module_invoke('other_module', 'block_view', 'other_modules_block_name_or_delta'); and then setting your $content appropriately.

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.