1

I'm just starting out with drupal and need some custom html for an intricate menu system. My plan is to override the html-generating functions in template.php.

My theme name is "Drupal subtheme" and the navbar I would like to target has the machine name "menu-usm-navbar-small". What should I name the functions that overrides the default html-printouts?

I think I have tried every possible combination of these. Some examples of what I've tried:

function drupal_subtheme_menu_link($variables) {
    return "foo";
}

function drupal_subtheme__menu_usm_navbar_small($variables) {
    return "foo";
}
1
  • If your theme's machine name is drupal_subtheme, your first example is right. You should clear the caches, at least clear the theme-registry.
    – Elin Y.
    Jul 2, 2014 at 15:08

1 Answer 1

0

It depends on what you want to target.

If it's the tree of the menu you can use theme_menu_tree :

function drupal_subtheme_menu_tree__menu__menu_usm_navbar_small($variables) {
   return '<ul class="menu">' . $variables['tree'] . '</ul>';
}

if it's the link, you can use theme_menu_link :

function drupal_subtheme_menu_link__menu__menu_usm_navbar_small($variables) {
   $element = $variables['element'];
   $sub_menu = '';

   if ($element['#below']) {
     $sub_menu = drupal_render($element['#below']);
   }
   $output = l($element['#title'], $element['#href'], $element['#localized_options']);
   return '<li' . drupal_attributes($element['#attributes']) . '>' . $output . $sub_menu . "</li>\n";
}

These functions need to be in template.php

7
  • I tried these examples but it did not work. The ul element still has the classes "menu nav" even though I replaced your class="menu" with class="menu hello hello".
    – mipmap
    Jul 2, 2014 at 15:37
  • The cache is cleared.
    – mipmap
    Jul 2, 2014 at 15:37
  • Is your theme activated and set defaut ? What do you get in the URL when you try to edit your menu "menu-usm-navbar-small" ? And what do you get in the URL when you edit your theme ?
    – pbonnefoi
    Jul 2, 2014 at 15:41
  • It is set to default and the url in Adminpanel > Menu > USM Navbar Small is localhost/usm/…
    – mipmap
    Jul 2, 2014 at 15:43
  • I made an update, can you try it ? I added menu (drupal_subtheme_menu_tree__menu__menu_usm_navbar_small)
    – pbonnefoi
    Jul 2, 2014 at 15:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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