I would love a little help setting up the ability to inject spans and imgs into a menu item anchor tag. I have been able to acheive this by hacking the common.inc file on line 1081 from:
return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'>'. ($html ? $text : check_plain($text)) .'</a>';

to:

return '<a href="'. check_url(url($path, $query, $fragment, $absolute)) .'"'. drupal_attributes($attributes) .'>'. ($html.$text) .'</a>';

I would like some help doing this with a module or via phpTemplate. Ideally though, I would like another input in the menu form to inject whatever html you might need rather than just including it as part of the anchor text (menu title).

The reason for wanting to do all this is that it would enable people to use Eric Meyer's pure css popups.

Thanks,

Jon

Comments

taslett’s picture

Hi Jon,
Here is something you could try, fell free to correct me if I am going down the wrong path:
In template.php file within your theme add:

function phptemplate_menu_item_link($item, $link_item) {
  _phptemplate_callback('menu_item_link', array('item' =>$item, link_item'=>$link_item));
}

then create a new file called menu_item_link.tpl.php:


  return l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array(), NULL, NULL, FALSE, TRUE);

In theory that should allow you to have html such as spans in your links.
You may have to change the filter settings to allow spans also.

Hope that helps
Tony.
-----------------------
www.csscreator.com

jon_hancock’s picture

Thanks, Tony.

I'll give that a shot.

Jon Hancock

Chuck Norris CAN believe it's not butter!

jon_hancock’s picture

Well, Tony, unfortunately, that seems to make the menus dissapear all together.

Jon Hancock

Chuck Norris CAN believe it's not butter!

taslett’s picture

Hi Jon,
instead of return try print in menu_item_link.tpl.php: print l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array(), NULL, NULL, FALSE, TRUE);

www.csscreator.com

taslett’s picture

Hi Jon,
Ok after a little playing around I found another way to do this.
in template.php add

function phptemplate_menu_item_link($item, $link_item) {
  $lnk= l($item['title'], $link_item['path'], isset($item['description']) ? array('title' => $item['description']) : array());
 return _phptemplate_callback('menu_item_link', array('lnk' => $lnk) );
}

then in menu_item_link.tpl.php add

<?php
$insert='<span>x</span>';
$start=strpos($lnk, '>');
if($start >0){
  $lnk=substr_replace($lnk, $insert, $start+1, 0);
}
echo $lnk;
?>

Hope this one works.
I put an x in the span so you could easily see that something was happening.

www.csscreator.com