I'm trying to seperate the primary tabs and secondary tabs, so I can basically insert them in different areas from each other. (this should be default, like primary and secondary links, IMHO)

So far I have this in a template.php

function tabs($a) {
 switch($a) {
  case 'primary' :
   print '<ul class="tabs primary">';
   print menu_primary_local_tasks();
   print '</ul>';
  break;
  case 'secondary' :
   print '<ul class="tabs secondary">';
   print menu_secondary_local_tasks();
   print '</ul>';
  break;
 }
}

Then wherever I want to insert a tab in page.tpl.php, i use the tabs() function i just defined, such as:

<?php if ($tabs != "") {
  tabs(primary);
  }
?>

So far everything is working, I managed to get the two tabs (primary & secondary) to appear where I want them. But there is a problem.
Whenever, for example, the secondary tab isn't available to that page, <ul class="tabs secondary"></ul> will be inserted into the code. Since there is no secondary menu on this or that page, that UL needs to not appear. Because it does, my styles for that class interfere with the layout.

While trying to figure out where those UL and CLASS definations are coming from, I found the function theme_menu_local_tasks() in menu.inc. As a test, I changed class="secondary" to class="secondaryX". However, in the page that the webserver serves, it still says "secondary". I tried overriding the function to the same effect. I also tried one of the tree functions but it too didn't stop the page from containing extra UL tags that I didn't ask for.

Comments

merlinofchaos’s picture

  case 'primary' :
   print '<ul class="tabs primary">';
   print menu_primary_local_tasks();
   print '</ul>';
  break;

Unless I'm completely misreading what you're saying, it's your code that's printing the <ul class="tabs primary">

You need to do this:

  case 'primary' :
   if ($tasks = menu_primary_local_tasks()) {
     print '<ul class="tabs primary">' . $tasks . '</ul>';
  }
  break;

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

merlinofchaos’s picture

A few other minor tips to push you toward Drupal consistency and code safety.

Your function 'tabs' should probably be renamed to something like phptemplate_tabs or somesuch -- this is to ensure you don't end up with a namespace collision by mistake. tabs is a very short function name and Drupal naming techniques don't generally allow a function to be named such. It's good to follow those practices even in your custom code.

Second, you should probably return the output from $tabs rather than actually printing it. While in your specific case you don't need to do this, doing so ensures that should you later change how you use your phptemplate_tabs() function, it will still be usable regardless.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]

gobblez’s picture

Thanks what you said worked. I wasn't even aware of the $tasks variable, it wasn't on the list on phptemplate's page. I renamed my function and made it return instead of print, like you suggested. I spent all my waking hours yesterday trying to seperate the tabs. :(

merlinofchaos’s picture

In that code, you're assigning the results of the function TO the $tasks variable; it's not something that's passed through. It could've been named $supercalifragilisticexpialidocious if you'd liked, but that's too much typing.

-- Merlin

[Point the finger: Assign Blame!]
[Read my writing: ehalseymiles.com]

-- Merlin

[Read my writing: ehalseymiles.com]
[Read my Coding blog: Angry Donuts]