0

I want to assign a specific menu in left sidebar block, based on the node type of the page currently being displayed. I think it should look something like this, but I am stuck.

function my_module_nodeapi(&$node, $op) {
  switch ($op) {
    case 'view':
      if ($node->type == "large_reptiles") 
      {
        //menu_set_active_menu_name('menu_reptile_menu');
        //menu_set_active_item('menu_reptile_menu');
      }
    break;
  }  
}
apaderno
  • 28,547
  • 16
  • 75
  • 90
ernie
  • 119
  • 10

1 Answers1

0

You can't use hook_nodeapi for that. You should instead create the block yourself in a module and based on the node print the menu.

function hook_block($op = 'list', $delta = 0, $edit = array()) {
  switch ($op) {

    case 'view':
        if (arg(0) == 'node' && is_numeric(arg(1))) {
          $node = node_load(arg(1));
        }
        if (!empty($node) && node->type == '...') {
          // Theme the menu you want
        }
        ...
        else {
          // Provide a default option
        }


    ....
  }
}
googletorp
  • 33,075
  • 15
  • 67
  • 82
  • Thanks for prompt reply! What if node comes in as /node_name instead of /node/9999? Is there an API to assign a menu to a block? – ernie Jun 02 '10 at 12:17
  • @ernie You can use modules to change the appearance of the url, but Drupal will always map nodes as node/[nid] internally. – googletorp Jun 02 '10 at 12:25