Hi,
I have 2 node types: typea and typeb. I want to show menu tabs for typea, but not for typeb.

function mymodule_menu() {
$items = array();
 
	
	$items['node/%node/tab1']        = array(
	   	'title'               => 'tab1',	
          	'page callback'       => 'theme_function_tab1',
       		'page arguments'      => array(1),
          	'type'                => MENU_LOCAL_TASK,
       		);

	$items['node/%node/tab2']        = array(
	   	'title'               => 'tab2',	
          	'page callback'       => 'theme_function_tab2',
       		'page arguments'      => array(1),
          	'type'                => MENU_LOCAL_TASK,
       		);
       			    	
return $items;
}

The problem is, that the tabs are shown on every node. How can I cell Drupal not to show the tabs on every node without manipulation the node.tpl.php?

Thanks

Comments

ziobudda’s picture

You can base the $items on the URL ($_GET['q'] and arg()). Say that you want to display tab1 only when the node is a multiply of 2 and your url si http://www.mydomain.com/node/1/

function mymodule_menu() {
$items = array();

   if (arg(1) % 2) {
    $items['node/%node/tab1']        = array(
           'title'               => 'tab1',   
              'page callback'       => 'theme_function_tab1',
               'page arguments'      => array(1),
              'type'                => MENU_LOCAL_TASK,
               );
  } else {
     $items['node/%node/tab2']        = array(
           'title'               => 'tab2',   
              'page callback'       => 'theme_function_tab2',
               'page arguments'      => array(1),
              'type'                => MENU_LOCAL_TASK,
               );
    }
 return $items;
}

Where:
arg(0) = node
arg(1) = 1

Obviously you lost the possibility to cache the $items.

M.

PS: this code is not tested but it's a start point.

Freelancer Senior Drupal Developer -- http://www.ziobuddalabs.it

Nick Lewis’s picture

Try this:

function mymodule_menu() {
  $items = array();
  // get the active node
  $node = menu_get_object();
  if ($node->type == 'typea') {
  // the local tasks here....  
  }                   
  return $items;
}

Be sure to rebuild the menu to test.
--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.onnetworks.com

--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.zivtech.com

glueckskind’s picture

Thanks for your responses but this works only for Drupal 5 and not for Drupal 6

Nick Lewis’s picture

You mean the other way around. menu_get_object() should result in a fatal error in drupal 5.

--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.onnetworks.com

--
"I'm not concerned about all hell breaking loose, but that a PART of hell will break loose... it'll be much harder to detect." - George Carlin
--
Personal: http://www.nicklewis.org
Work: http://www.zivtech.com

thx538’s picture

The solution is explained here: http://drupal.org/node/218692