4

The issue is that I have a Menu Block with parent items that don't yet have child menu items, but eventually might. I want to display another block in place of the menu block if the menu block is not on a particular page. I have tried rules, rules bonus blocks, context, even conditions in my page templates but I am a PHP novice and so far it doesn't seem possible to create a condition based on a block's visibility. I hope that makes sense! Any help much appreciated! I am using D7.

2

I was able to do this with panels, view blocks and a custom PHP visibility condition. I think Panels is trivia. You could do this with Drupal's built-in block administration.

I had a news block that would show up on the city page. It would display all the news of the city. If there was no news for that city, it would display [another] news block for that state. If there was no news for that state, it would display [another] news block for the country.

Each of these block was a view. In the PHP visibilty I would check for views results using the views_get_view_result($name, $dispay_id = NULL [, $args])

So the county block would check if the state and city block view returned any results, if FALSE (no results) then it would get displayed. State would check if city block view return any results, if FALSE (no results) then it would get display.

If you blocks are not views, then I don't know how to solve the problem easily (unless the last block is the only one that is not).

  • Thanks for your answer! Unfortunately the Menu Block module is not a view, and is dependent on the core Menu module. In my experience views and menus don't mix. The secondary display is a view though. – Danielle Jul 8 '11 at 5:05
  • so if menu (block) does not have any links then display view block? – iStryker Jul 8 '11 at 11:38
1

One of my blocks was not a view but a custom block generated via module, so create a view which would generate the similar content, at least could list the items or give the total count of items. Then I checked if there is any result returned by views_get_view_result($name, $dispay_id = NULL [, $args]), if yes then don't show this block else show the block.. and it worked for me. Hope this helps someone in need.

0

I had very similar problem with Menu Block module so I wrote simple Context module/plugin Context Active Menu Depth that sets appropriate context when specified condition (menu depth, menu name and has_children) are met. Code is still experimental but you'll get the idea. In my case I needed to display replacement block if Menu Block with 2nd level of links is not present.

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.