By thesaint_02 on
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
Kludge
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
Doesn't work
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.
Childrens Page
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. :-)
Anyone figure out how to do this yet?
bump...
It's another hack, but use #
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
Very hacky solution using jquery
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:
and then in my menu_hack.js:
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
Charles
Drupal development, Cape Town, South Africa
Menu Firstchild
If you use D6, you can try:
http://drupal.org/project/menu_firstchild
How to create a Menu item
How to create a Menu item which is just a placeholder?
.dan. is the New Zealand Drupal Developer working on Government Web Standards
modify page.tpl.php
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):
D7: use Void Menu
Void Menu allow to set custom href attributes
http://drupal.org/project/void_menu (Drupal 7 only)