Can I change the menu_link theme for a specific menu?

I would like to add channels ("|") between the menu items for one of the menus on my Drupal 7 site (the theme name is "thompson"). I decided that the best way to do this is to create a function in my template.php file called thompson_menu_link. I did this, and it successfully changes the menu, but changes the entire menu. Is there a way to do this for only one menu on my site?

Currently, I have used admin pages to add a footer (URL: menu-footer-menu) to the footer block. Should I call it another way?

+6
source share
3 answers

The Drupal core seems to provide theme menu links by menu name . The following theme function should work for the main menu

THEMENAME_menu_link__main_menu() 

Alternatively, you can use the Menu Block module to create menu blocks. Among other things, the module creates additional topics. From the README module:

The menu block uses the theme functions of the Drupal main menu. However, it also provides recommendations for choosing a topic that can be used to override any of the theme's function calls ....

  • theme_menu_link () can be overridden by creating one of the following:
    • [topic] _menu_link __ [menu name] ()
    • [topic] _menu_link__menu_block ()
    • [topic] _menu_link__menu_block __ [menu name] ()
    • [topic] _menu_link__menu_block __ [block identifier] ()
+2
source

I messed up the thompson_menu_link() function a bit. I don't like the way I did it, but he did the job. Basically, it reads in the menu name and uses a conditional expression to return the <li> element followed by the pipe. Here is the whole block:

 function thompson_menu_link(array $variables) { $element = $variables['element']; $menuName = $variables['element']["#original_link"]["menu_name"]; $sub_menu = ''; if ($element['#below']) { $sub_menu = drupal_render($element['#below']); } $output = l($element['#title'], $element['#href'], $element['#localized_options']); if ($menuName == "menu-footer-menu" && !in_array("last",$element['#attributes']['class']) { $finalString = '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>|\n"; } else { $finalString = '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n"; } return $finalString; } 
+2
source

the best way to do this is to install the following module:

http://drupal.org/project/menu_attributes

This module allows you to add special classes to some menu entries, so you just need to add the rightpipe class and define this class as:

 .rightpipe { border-right: 1px solid black } 

or

 .rightpipe { background: url(1pixel_line_separator.png) no-repeat center right } 
0
source

Source: https://habr.com/ru/post/895695/


All Articles