Greetings, thankyou I am enjoying your great DHTML menu module!

I am learning to theme drupal and I am a non-programmer.

I have found this code snippet from http://drupal.org/node/227607

function phptemplate_menu_item($mid, $children = '', $leaf = TRUE) {
  $item = menu_get_item($mid); // get current menu item
  // decide whether to add the active class to this menu item
  if ((drupal_get_normal_path($item['path']) == $_GET['q']) // if menu item path...
  || (drupal_is_front_page() && $item['path'] == '<front>')) { // or front page...
    $active_class = ' active'; // set active class
  } else { // otherwise...
    $active_class = ''; // do nothing
  }
  $attribs = isset($item['description']) ?
array('title' => $item['description']) : array();
  $replace = array(' ', '&');
  $attribs['id'] = 'menu-'. str_replace($replace, '-', strtolower($item['title']));
  return
'<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . (menu_in_active_trail($mid) ? ' parent' : '') . $active_class .'" id="'. $attribs['id'] . '">' . menu_item_link($mid) . $children ."</li>\n";
}

After putting it into my theme's template.php it create a unique css ID for all the menu items from the core menu module which is perfect for any themer's requirements.

I am curious why this does not work for this module and whether you would consider implementing this as I think its a big disadvantage to drupal themers.

Cheers again.

Comments

imp7’s picture

I just learnt that themes can certain module functions, I just wish I could write functions like this myself!
This code works fine for others who are looking to do get some themes cranking.. :)

function phptemplate_dhtml_menu_item($mid, $children = '', $leaf = TRUE) {
  $item = menu_get_item($mid); // get current menu item
  // decide whether to add the active class to this menu item
  if ((drupal_get_normal_path($item['path']) == $_GET['q']) // if menu item path...
  || (drupal_is_front_page() && $item['path'] == '<front>')) { // or front page...
    $active_class = ' active'; // set active class
  } else { // otherwise...
    $active_class = ''; // do nothing
  }
  $attribs = isset($item['description']) ?
array('title' => $item['description']) : array();
  $replace = array(' ', '&');
  $attribs['id'] = 'menu-'. str_replace($replace, '-', strtolower($item['title']));
  return
'<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) . (menu_in_active_trail($mid) ? ' parent' : '') . $active_class .'" id="'. $attribs['id'] . '">' . menu_item_link($mid) . $children ."</li>\n";
}
imp7’s picture

Status: Active » Closed (fixed)
imp7’s picture

Status: Closed (fixed) » Active

I just jumped the gun, when the overriding of dhtml_menu_item I am guessing that the javascript doesn't know what to select anymore.

Any help on giving each menu item in the list an id relative to their menu name / position / state would be much appreciated.

ckidow’s picture

subscribing

imp7’s picture

Well over the time to try and find a good method I have also upgraded to 6.x and there is a sweet as module called

http://drupal.org/project/menu_attributes

You can set a bunch of custom attributes for all menu items individually so its just a matter of setting up some simple css.

imp7’s picture

Status: Active » Closed (fixed)