views:

410

answers:

1

I'm trying to generate unique id's on the 'a' tag of the menu item so that I can implement Popups API.

This is what my function in template.php looks like:

function phptemplate_menu_item_link($link) {
  if (empty($link['options'])) {
    $link['options'] = array();
  }

  // If an item is a LOCAL TASK, render it as a tab
  if ($link['type'] & MENU_IS_LOCAL_TASK) {
    $link['title'] = '<span class="tab">'. check_plain($link['title']) .'</span>';
    $link['options']['html'] = TRUE;
  }

  if (empty($link['type'])) {
    $true = TRUE;
  }

  //get unique id from menu item title
  $css_id = phptemplate_id_safe(str_replace(' ', '_', strip_tags($link['title'])));

  //set unique id for link
  if ($link['menu_name'] == 'primary-links') {
    $link['options']['attributes']['id'] = 'id-' . $css_id;
  }

  return l($link['title'], $link['href'], $link['options']);
}

I'm debugging w/ Zend and the conditional statement works. I've cleared the cache, my browser cache, and rebuilt the menu multiple times, but can't seem to get it to work.

Just as a reference, phptemplate_id_safe is custom (obviously) and works fine.

A: 

You might want to have a look at menu_attributes or this forum post.

xkcd150

related questions