Is it possible to create a menu item that is not clickable (does not have a path), under which there would be normal sub-items that are clickable (do have paths)?

Comments

sraisz’s picture

I'm new to Drupal , coming from Joomla world where this is quite simple. Did you ever get a solution to this query?

robertgarrigos’s picture

This is a way for 4.6.

I needed a way to achive this behavior with an old project of mine made on drupal 4.6. The only way I found, without patching the core, is overriding the proper theme function, in menu.inc, that renders the link. In 4.6 this function is theme_menu_item_link($item, $link_item). Use this function in your theme to include a conditional to avoid the l() function for the path you don't need the link. In my case, with a phptemplate theme, I used this:

function phptemplate_menu_item_link($item, $link_item) {
  if ($link_item['path'] != 'hotels/languages') {
   return l($item['title'], $link_item['path'], array_key_exists('description', $item) ? array('title' => $item['description']) : array());
  }
  else {
    return $item['title'];
  }
}

Thus, the parent menu item with path 'hotels/languages' will render only as its title, no link, although it would have any children items you need. The only problem is that you would need to know beforehand the path of the item you don't want to be clickable. Otherwise, it will do the job.
---
Robert Garrigos
Professional site: robert.garrigos.cat
Catalan Drupal Users Group: drupal.cat

Qudsiyya’s picture

Any idea how to do it in drupal 5?

bluefooz’s picture

Hi there, I'm also looking for a way to create placeholder/container/no-path menu items in Drupal 5.3. Any leads would be much appreciated. Thank you.

[Edit]: I'm finally settled with the solution from drupal.org/node/128618.

najibx’s picture

This does the trick. Put in template.php

function phptemplate_menu_item_link($item, $link_item) {
  $path = explode("#",$link_item['path']);
  if($path[0])
    return l($item['title'], $path[0], !empty($item['description']) ? array('title' => $item['description']) : array(),  isset($item['query']) ? $item['query'] : NULL, $path[1]);
  else
    return '<a href="#">'.$item['title'].'</a>';
}

i'm now looking for d6

andrewsuth’s picture

D6 solution here

NathanFrankel’s picture

Is it possible to have some menu items with sub-items to be clickable, while other menu items with sub-items are not? I am working on a site where this would be ideal.

Also, the PHP code for D5 template.php file didn't work for me. Has anyone else gotten it working?

Thanks.

Nathan

Anonymous’s picture

Drupal special menu items Module does just that.

http://drupal.org/project/special_menu_items

amitgarg’s picture

Hi,

put the below line in path & put your desire title

http://#

Thanks,
Amit Garg
http://highpixel.in

LIQUID VISUAL’s picture

Thanks to all, esp Amit.

Check out the Mooney's Bay Webcam, at http://liquidvisual.ca

bruindelts’s picture

This actually throws an error on a few versions of Firefox (when you click on the menu item, an alert box pops up saying "The URL is not valid and cannot be loaded.").

bruindelts’s picture

(as said a little earlier) This actually throws an error on a few versions of Firefox (when you click on the menu item, an alert box pops up saying "The URL is not valid and cannot be loaded.").

meigwil’s picture

I have a tiny piece of jQuery running to fix this:

$('li.menu-2598 > a').click(function(e){e.preventDefault()});

Each menu item has a unique class, in this case menu-2598. The > is important so as not to allow the child a elements to be affected.

professor_b’s picture

I am doing the same thing but it does not work well in terms of SEO or users/bots with Javascript disabled. Still searching for a sound, non-hacky solution. people can still access the placeholder item by typing it in the browser location bar.

I would gladly write a module that detects if the current menu items has children, and if it does, simply render a ul element containing the navigation. But I am at best a novice module author. Drupal 8 will probably be out before I solve this, and hopefully it will provide a solution.

samsterlin’s picture

Thank you very much amitgarg

amontero’s picture