开发者

How can I open a Drupal 6 submenu programmatically?

I have a menu with two levels, the second level shown in the secondary menu.

How can I open the second menu level programmatically from pages other than those linked in the menu?

I've looked at the开发者_如何学Pythonme_preprocess_page and others but can't figure out how the change the menu item state from collapsed to active.


Could your problem be solved by just putting the items in the menu and not enabling them?

If not, you might check out the Menu Trails module, as it allows a lot more flexibility for setting active menu items.


I've been messing around with a similar issue for a while.

There's some documentation here: http://api.drupal.org/api/group/menu/6 but it's a bit sketchy on some points.

This function seems like it will do the trick: http://api.drupal.org/api/function/menu_navigation_links/6. See how you can set the level (as an argument) so the menu should render what you want.

This may not be exactly what you want but hopefully will point you in the right direction!


Answering my own question, this node api hook does it.
Inspired by the Menu Trails module, Mike mentioned.

function phptemplate_nodeapi(&$node, $op) {
  if($open_menu_for_this_node && $op == 'view') {
    $item = menu_get_item();
    $item['href'] = $menu_item_to_open;
    menu_set_item(NULL, $item);
  }
}


Outside of a node context something like this will work:

function HOOK_init() {

  if (arg(0) == 'exhibits' && arg(2) == 'publications') {
    $normal_path = drupal_get_normal_path( arg(0) .'/'. arg(1));
    $item = menu_get_item();
    $item['href'] = $normal_path;
    menu_set_item(NULL, $item);
  }

}

this particular example is looking to make exhibits/XXXXX menu active when exhibits/XXXXX/publications is the path. exhibits/XXXXX/publications isn't in the menu in question, but exhibits/XXXXX is.

drupal_get_normal_path() just converts exhibits/XXXXX to node/NNNN

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜