2

I'm trying to implement a dropdown menu in my custom theme. At the moment, this means I have a region for the primary and another region for the secondary menu.

According to the design I would like implement, the description of a menu element should be visible - but only for sub-menu elements, like in this menu: Dropdown menu in ZURB's Foundation

My problem is the following:

I can't find a way to handle different levels of menus accordingly, i.e. to add the markup of the descriptions only where necessary and the different classes on ULs.

How should I implement this kind of menu?

[I've installed the Menu Block module for some help with this. It adds several new hooks that might be useful, but we will see...]

Thanks for checking out this question!

  • 1
    So, the text "Small Example" would be the child menu item of "Nav Item 2" (and the example text would be the description for the menu item "small example") and would be exposed when "Nav Item 2" is hovered on? What would happen to a tertiary level menu item? And these are both part of the site's Main Menu? How is the secondary menu relevant in this situation? What have you tried so far to accomplish this? Most likely you will need to implement a customization of theme_menu_link() in order to add in the description for the secondary-level menu items. – sheena_d Feb 7 '12 at 14:57
  • @sheena_d: yes, your assumptions in your first question are right. The behaviour of tertiary level of menus isn't defined yet (anyway if I know how to handle depth in this situtation, I will be able to figure out). The secondary menu is relevant just because it has to work in the same way, the styling will be different only a little. I've tried working with theme_menu_link() and theme_menu_tree(), didn't figured out how to check for level depth, but just saw a comment on drupal.org which might solve this. – Scorchio Feb 7 '12 at 15:41
4

Within your theme's template.php, you can override the theme_menu_link() function.

Target the $variables['element']['#original_link']['depth'] variable to check for the depth of the current menu item.

The variable $variables['element']['#original_link']['localized_options']['attributes']['title'] holds the "description" value entered on the menu item's edit page.

  • Yeah, that's it, thanks! Could you point me to some documentation about $variables['element']? theme_menu_link()'s documentation lacks information (see the issue I've opened: drupal.org/node/1431570) – Scorchio Feb 8 '12 at 9:21
  • 1
    Detailed information about available variables is not included in the API documentation by design, because every active module or theme on the site can manipulate the variables, there's no way to accurately document that information. You can see all of the available variables by installing the Devel module (drupal.org/project/devel) and adding kpr($variables); to your theme function in template.php When you refresh a page that includes your menu, you will see the available variables printed out with Krumo. – sheena_d Feb 8 '12 at 14:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.