Hello.
In a standard drupal theme, I have 3 primary links:

  • Overview: goes to front page
  • Test View: goes to a view listing
  • Background: goes to a page node

The links look like "/", "/test-view", and "/background"

The issue: In my custom theme, I need to parse $primary_links into an altered list with added span tags. the href of the links look like "<front>","test-view","node/2". How do I correct this?

Thanks much. :)

Comments

soundsational’s picture

Are you using Pathauto module: http://drupal.org/project/pathauto

owntheweb’s picture

Yes. I think there's an issue with my template functions. It looks and works 'right' when using standard theme() function, but not in my own. Here's what I have. Do you see an area I can improve upon to get this working?

in page.tpl.php:

if (isset($primary_links)) { print get_summit_primary_links($primary_links); }

in template.php:

//some parts referenced from "Theming primary and secondary links": <a href="http://drupal.org/node/319292">http://drupal.org/node/319292</a>
function get_summit_primary_links($primary_links) {
	if (!count($primary_links)) {
		return '';
	}
	
	return menu_create_menu($primary_links);
}

function menu_create_menu($links) {
	//print_r(menu_navigation_links('primary-links'));
	//print_r(menu_tree_page_data('primary-links'));
	$the_menu = "\n<ul>\n";
	
	foreach ($links as $index => $link) {
		$the_menu .= "\t<li";
		 if (stristr($index, 'active')) {
		 	$the_menu .= " class=\"selected\">";
		 } else {
		 	$the_menu .= " class=\"unselect\">";
		 }
		 
		 $the_menu .= "<a href=\"/" . str_replace("<front>","",$link['href']) . "\"><span>" . $link['title'] . "</span></a></li>\n";
	}
	
	$the_menu .= "</ul>\n";
	
	return $the_menu;
}

Worlds to explore. Worlds to create.
Blog: http://www.christopherstevens.cc/blog
Twitter: http://www.twitter.com/owntheweb

owntheweb’s picture

Hmmm. I think the secrets are in the l() function. I'm still looking into it, but any thoughts on how to make this work if I have to have a span tag inside the tags?

Worlds to explore. Worlds to create.
Blog: http://www.christopherstevens.cc/blog
Twitter: http://www.twitter.com/owntheweb

owntheweb’s picture

Success!

This function magically turns "" and "node/2" into "/" and "/background" :)

print url($some_link);

Here's the updated template.php file that let me customize my primary nav menu for all who may find this useful:

//special thanks to "Theming primary and secondary links": <a href="http://drupal.org/node/319292">http://drupal.org/node/319292</a>
function get_summit_primary_links($primary_links) {
	if (!count($primary_links)) {
		return '';
	}
	
	return menu_create_menu($primary_links);
}

function menu_create_menu($links) {
	$the_menu = "\n<ul>\n";
	
	foreach ($links as $index => $link) {
		$the_menu .= "\t<li";
		 if (stristr($index, 'active')) {
		 	$the_menu .= " class=\"selected\">";
		 } else {
		 	$the_menu .= " class=\"unselect\">";
		 }
		 
		 $the_menu .= "<a href=\"" . url($link['href']) . "\"><span>" . $link['title'] . "</span></a></li>\n";
	}
	
	$the_menu .= "</ul>\n";
	
	return $the_menu;
}

Worlds to explore. Worlds to create.
Blog: http://www.christopherstevens.cc/blog
Twitter: http://www.twitter.com/owntheweb