I'm trying to convert an XHTML / CSS template into a Drupal theme. However, I've run into some problems. The primary link structure for the template is this:

<ul align="center">
<li align="center"><a href="index.php"><span>Home</span></a></li>
</ul>

Now the problem I'm having is that when I use:

 if (isset($primary_links)) :
print theme('links', $primary_links, array('class' => 'links primary-links'))
endif; 

It outputs:

<ul class="links primary-links" align="center"><li class="menu-115 active-trail first last active"><a href="/node" title="" class="active">Home</a></li>
</ul>

It displays the nav bar incorrectly because of the lack of <span></span> tags between the text. Is there any way to tell Drupal to put these tags in between the text? Any help is appreciated! :)

Comments

styro’s picture

Override theme_links() in your theme, or adjust the CSS to fit the HTML.

See http://drupal.org/node/341628 for info about theme overrides.

--
Anton

nineteen’s picture

Right, I have this problem - I've done this etc and it all works.. Right..

But now I want to also have a second theme_links() function to add extra HTML for another navigation..

How can I do this?

styro’s picture

You could either add a conditional check inside your override that varies the HTML depending on the circumstances,

or

You could create a second copy of the override (eg yourthemename_links2() ) and call it differently from your page.tpl.php

eg:

<?php
// $other_links is just an example - change it to whatever you are using
if (isset($other_links)) :
print theme('links2', $other_links, array('class' => 'links other-links'))
endif;
?>

Note the theme('links2', .... ) bit calls your new theme function.

I'd recommend the first option to reduce code duplication.

--
Anton

nineteen’s picture

Second method does not work.. I'll just make a conditional statement :(

enkee’s picture

This may be because you need to register function by declaring it in THEMENAME_theme() inside your template.php. As in:

function THEMENAME_theme() {
  return array(
    // register
    'custom_primary_links' => array(
      'arguments' => array('links' => NULL, 'classes' => array('class' => 'links primary-links'))
    ),
}

Then simply add another function to your template.php, which will actually do the job:

// define
function THEMENAME_custom_primary_links($links = NULL, $classes = array('class' => 'links primary-links')) {
  // this is very silly customization
  $linksOutput = '<ul>';
  foreach ($links as $link) {
    $linksOutput .= '<li><a href="' . $link['href'] . '">We all look the same</a></li>';
  }
  $linksOutput .= '</ul>';
  return $linksOutput;
}

Now, rebuild theme registry (http://drupal.org/node/173880#theme-registry) and your new theme function is accessible, for example from page.tpl.php:

if ($primary_links) {
  // call
  print theme('custom_primary_links', $primary_links);
}

Notice how custom_primary_links appears in registering part, function definition and final theme function call.

Yep say no to conditional checks!

kmark’s picture

In short, I'm trying to get tags around each nav "part".

kmark’s picture

Thanks! I'll try that!

carn1x’s picture

Ok I copied the theme_links() to my theme's template.php as mytheme_links() however no changes I make are taking effect.

Tried flushing the cache a billion times. I am using Primary Links as a block however instead of built into the page.tpl.php, will this make a difference?

Is there any way to figure out what template files are being parsed?

Thanks :)