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

yrocq’s picture

Assigned: Unassigned » yrocq

Try 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 :

return '<li style="display:inline" class="'. $class .'" id="'.$id.'">'. theme('menu_item_link', $link) ."</li>\n";

by

return '<li style="display:inline" class="'. $class .'" id="'.$id.'"><span>'. theme('menu_item_link', $link) ."</span></li>\n";

It should work.

yrocq’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

mhendrik0031’s picture

Version: 6.x-1.0-beta2 » 6.x-1.5

The 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.

function mytheme_menu_item_link($link) {
  if (isset($link['href'])) {
	$link['title'] = '<span>' . check_plain($link['title']) . '</span>';
    $link['html'] = TRUE;    
    // Pass in $link as $options, they share the same keys.
    $output .= l($link['title'], $link['href'], $link);   
	return $output;
	}
}
codenamerhubarb’s picture

Thanks mhendrik0031, this worked for me!