Closed (fixed)
Project:
Dynamic Persistent Menu
Version:
6.x-1.5
Component:
Code
Priority:
Normal
Category:
Support request
Assigned:
Reporter:
Created:
11 Jan 2009 at 20:55 UTC
Updated:
24 Mar 2011 at 03:41 UTC
Hi there. This module is great, but I am having difficulty figuring out how to get a tag inside of the anchor. Basically, I want <li><a><span></span></a></li>.
The code i would use for normal primary links would be something like:
function phptemplate_menu_item_link($item, $link_item) {
$title = '<span>' . $item['title'] . '</span>';
return l($item['title'], $link_item['path'], !empty($item['description']) ? array('title' => $item['description']) : array(), isset($item['query']) ? $item['query'] : NULL, NULL, FALSE, TRUE);
}
or
function phptemplate_links($links, $attributes = array('class' => 'links')) {
$output = '';
if (count($links) > 0) {
$output = '<ul'. drupal_attributes($attributes) .'>';
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$class = $key;
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$class .= ' first';
}
if ($i == $num_links) {
$class .= ' last';
}
if (isset($link['href']) && $link['href'] == $_GET['q']) {
$class .= ' active';
}
$output .= '<li class="'. $class .'">';
if (isset($link['href'])) {
// Pass in $link as $options, they share the same keys.
$link['html'] = TRUE;
$output .= l('<span>'. check_plain($link['title']) .'</span>', $link['href'], $link);
}
else if (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
}
$i++;
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
Any chance you could help me with adapting something like this for use with your module?
Thanks.
Comments
Comment #1
yrocq commentedTry to copy the function theme_dynamic_persistent_menu_menu_item to the template.php file in your theme directory, and rename it to phptemplate_dynamic_persistent_menu_menu_item. You can then replace the line :
by
It should work.
Comment #2
yrocq commentedComment #4
mhendrik0031 commentedThe suggested code puts the span tags outside the anchor tags instead of inside. Since I have been spending hours on this subject so I might as well contribute my findings. The following code works for me.
Comment #5
codenamerhubarb commentedThanks mhendrik0031, this worked for me!