[development] Fwd: How to add comment under menu items

Erik Stielstra info at erikstielstra.nl
Wed Mar 17 16:39:41 UTC 2010


I did create what is called Speaking Navigation. You can see the result in the primary menu here: http://sintmartensonsbeekkwartier.nl/
I wrote an article on this: http://wizzlern.nl/drupal/speaking-navigation-drupal The article is in Dutch but the code is PHP ;)

Erik Stielstra



On 17 mrt 2010, at 09:28, Cédric Joubert wrote:

> hi,
> 
> I'm surprised, i did not receive any response... while i am sure, the code below is not very nice ;-)
> 
> any idea to help me do that in a good and correct Drupal way please ?
> 
> Cédric
> 
> ---------- Forwarded message ----------
> From: Cédric Joubert <cedjoubert at gmail.com>
> Date: 2010/3/6
> Subject: How to add comment under menu items
> To: development at drupal.org
> 
> 
> Hi,
>  
> I'm new on Drupal and I would like to know how can I make properly such comment on items Menu please ?
>  -> each first row is a link and each 2nd row is a comment...
>  
> - Menu 1
>   (my explanation)
>  
> - Menu 2
>   (other explanation ...)
> ...
>  
> The only solution i've found is to do that (below)... but i'm sure it's not a property way...
> - the only constraint i have is to have the abbility to get the Description field in the underlying menu to display a dynamic comment.
> but actually, the only trick I've found to get the Description is to parse the HTML string to retrieve the "title" tag to get my text.
> Not very cool, i think...
> - actually, to determine the underlying nodes menu, i'm testing her names... is there another way to do that ?
>  
> Can you help me please ?
>  
> Regards
> Cédric
>  
>  
> function myTheme_menu_item($link, $has_children, $menu = '', $in_active_trail = FALSE, $extra_class = NULL) {
>   $class = ($menu ? 'expanded' : ($has_children ? 'collapsed' : 'leaf'));
>   if (!empty($extra_class)) {
>     $class .= ' '. $extra_class;
>   }
>   if ($in_active_trail) {
>     $class .= ' active-trail';
>   }
>   $css_id = strip_tags($link);
>   
>   // test the node for which i want to add comment
>   if (stripos($link, 'MyMenu1') > 0 || stripos($link, 'MyMenu2') > 0) {
>     $rec = 'title="';
>     $i = stripos($link, $rec);
>     if ($i > 0) {
>        $j = strpos($link, '"', $i+strlen($rec));
>        if ($j > 0)
>          $title = substr($link, $i+strlen($rec), $j-$i-strlen($rec));
>     }  
>   }
>   
>   $title = ($title != "") ? '<div class="views-field-created"><h0>&nbsp;&nbsp;&nbsp;&nbsp;[' . $title . ']</h0></div>' : '';
>   return '<li class="'. $class .'">'. $link . $menu ."</li>\n" . $title;
> }
> 



More information about the development mailing list