Hello,

This is a very useful module - I have it installed and working - now the only thing I want to do is restrict the visibility of the block to pages/links that are contained within the block....e.g. I have the following menu:

Course
- Description
- Benefits
- Format

Now I want this menu block to only show on these pages - i.e. the Course, Description, Benefits or Format page - should I be playing around with mlids and plids or is there a more obvious way?

Comments

benkewell’s picture

i'm also looking for ways to do exactly that
it'll be nice if this function can be implemented per block within the module

benkewell’s picture

it seems like by setting Starting level of a block to be 2nd level or deeper will do the same.
in that case it will be shown only on pages of 2nd level or deeper under the selected parent menu item

but if starting level is 1st, it's always shown.
is it possible to make the scope of visibility as an option?

sushilmasti’s picture

I ended up using the submenu tree module and it worked using a combination of sibling menu and submenu

Renee S’s picture

@Ben Unfortunately the menu will not only display on one level. If I set it to be 3, it will show up on 3, 4, 5+ but containing all the items from 3. This is great for main menus, but not for section menus - I want it to go away when the user goes into 4 or 5.

Renee S’s picture

I ended up doing it the slightly-painful way, but it works:

$match = FALSE;

$menuInfo = menu_get_active_trail();

if ($menuInfo[1][link_path] == 'students' && !isset($menuInfo[3])) 
{
    $match = TRUE;
}
return $match;
brian_c’s picture

This would definitely be useful functionality to have; to have Starting Level 1+ only show the menu block conditionally if it contains an active item, exactly how 2+ and higher work.

A common use case for this would be if you have a flat, single level of Secondary Links (or other menu) you are displaying in your footer, and want to show a sub-menu in your sidebar of the footer items when one is selected, but ONLY when one is selected.

One might then ask, what if you DO always want the menu block displayed? Well first of all, I would submit this use case is already covered by Drupal core in the form of the theme layer's Primary and Secondary links; these always contain the first level and only the first level of their respective menus. And if Menu Blocks would like to continue offering this functionality, it should be a simple matter of adding an "always display menu" option, no?

I needed to implement the use case I described above (the footer links conditionally showing a sidebar block when active), so I used the following workaround:

I created a dummy parent for our footer links, named it "Utility", and made it link to <front> (because you have to link it SOMEWHERE), then disabled it. I then added all the footer links as children of it. Now we can create a footer menu that always displays, by setting Parent Item to our Utility item and Starting Level 1+, and can create a conditional sidebar menu by setting Parent Item to root and Starting Level 2+. Oh, and one problem that linking Utility to <front> caused was that the sidebar menu shows up when on the home page.. this was fixed by simply setting it not to display on <front> in the standard Block settings.

TommyK’s picture

I also think Menu Block would be well served to offer this functionality. I was able to use Submenu Tree as in comment #3 above to achieve the desired results.

Kylian-1’s picture

I had the same request but I found this useful snipped (not so the hard way):

<?php
  $match = FALSE;

  // block is visible if the node has the following active menu
  $menu = 'menu-my-menu';

  if (menu_get_active_menu_name() == $menu){
    $match = TRUE;
  }

  return $match;
?>

See: http://drupal.org/node/584984

JohnAlbin’s picture

Issue summary: View changes
Status: Active » Closed (won't fix)