How can i add empty menu items that act only as parents for other items and don't have a path? The path of a menu item is a required field.
Is there a "special" path or node that has the meaning "stay on current page". I could then test against this path in the theming function for menu items and output only the menu title.

Comments

kbahey’s picture

You can try a kludge and put the path as

javascipt:void(0);

--
Drupal performance tuning and optimization, hosting, development, and consulting: 2bits.com, Inc. and Twitter at: @2bits
Personal blog: Ba

thesaint_02’s picture

Since 'javascipt:void(0);' (with an 'r') gets inserted as a parameter for "q", this doesn't work. Instead, the "page not found" page is shown.

jeffbellamy’s picture

I just make a page with the children links on it. That way your user is always going where they want and they don't dead end anywhere.

The advantage of this approach is that a ten year old can do it. :-)

sgwealti’s picture

bump...

ca_grover’s picture

It's another hack, but use # as your path.

This would result in http://yoursite.com/index.php?q=# which simply means go to the top of the page - the q parameter would be empty in this case.

The only catch I can think of would be if Drupal escapes the path before navigating to it..... but I'm guessing not because it IS a path afterall... :)

HTH

foxtrotcharlie’s picture

I've managed to solve this by using jquery. You first need to have jquery working. Your menu items that you don't want to go anywhere, you can set their paths to any value, as we will replace them using jquery.

Then, I created a function that selects all menu items based on the title attribute that they have, and then adds a href attribute of "javascript: void(0);"

BTW - I'm still using Drupal 4.7 for this site, which is why I have to use JQ instead of $. Drupal v5 comes with jquery built in, AFAIK.

So in my template.php I have:

drupal_add_js('themes/tipsmain/js/menu_hack.js');
drupal_add_js('modules/jquery47/jquery-modified-compressed.js');

and then in my menu_hack.js:

// To run the code on page load
if (isJsEnabled()) {
  addLoadEvent(replace_null_menu_items);
}

function replace_null_menu_items  () {
JQ("a[@title=About Us]").attr("href","javascript: void(0)");
JQ("a[@title=Research]").attr("href","javascript: void(0)");
}
function aFunction (){}

So for links with the title attribute = "About Us" and "Research", clicking the menu link will keep you on the same page.

I'm sure there's a more elegant solution, but it works for me...

Charles

www.parkroad.co.za

anrikun’s picture

If you use D6, you can try:
http://drupal.org/project/menu_firstchild

ranvir.prasad’s picture

For Drupal 6, one can also add the following code in the head section of the page.tpl.php (found in the concerned theme folder):

<script type="text/javascript">
  $(document).ready(function(){$('.sf-with-ul').attr("href","javascript: void(0)");});
  </script>
jibus’s picture

Void Menu allow to set custom href attributes

http://drupal.org/project/void_menu (Drupal 7 only)