Hi all,

I would like to have a menu item which acts only like a placeholder, i.e. a label, not leading to any node. The only thing it should do is open up the list of items which are underneath. For instance, it could read: "Check these", and then, upon clicking, the "text 1", "text 2" etc. labels would show.

I can't manage to get this done, because every menu item requires a path, apparently. So, is there a way around??

I'm using Drupal 5.1.

Ludo

Comments

modul’s picture

Oops... Did I ask a tough one?

Ludo

neocisco’s picture

I think you can use DTHL Menus module for something like that. It lets you only see a menu item content when it has no "childs". Let me show you an example.
Having this menu structure:

Main
-Sub1
--SubSub1
-Sub2
-Sub3

With this module, when you click Main it deploys the whole branch, but shows no content.
And when you click Sub1 it deploys SubSub1, but also shows no content.
You'll only see content when you click items SubSub1, Sub2 and Sub3.
I don't know if that's exacly what you're looking for.
Greetings.

modul’s picture

Yes, Spartanbeast, thanks for your reply (I suppose you meant "DHTML Menus"), that is more or less what I was looking for. But is something like this really impossible in Drupal-out-of-the-box? Sounds so weird, that one would actually have to install a module just to have a separating line in between menu groups, or to have a non-linked menu item, as I was trying to get?? I'm quite happy with the menu as it is, but I would like to have this possibility to have something just serve as a placeholder. Any ideas, anyone?

Ludo

dman’s picture

If the functionality you want is DHTML, then yes, you use a module like DHTML to add it. In-page updates and expandy menus are DHTML, not HTML.

If you don't think you want DHTML, think about what you are asking for a bit harder.

If you want a 'unlinked' menu item/subtitle, then clicking on it will do nothing, and not show the sub list.

If you DO want clicking on it to show a page displaying the expanded sub-items ... what should the rest of that page look like? What would you expect the URL or bookmark to that 'page' to be?

It's an old puzzle I've had to explain as an info-architect to clients many times - you've chosen a title for a section, and you've given a bunch of pages that live within that section, but what do you want people to see when they just click on that section title??

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

modul’s picture

Thanks for your reply, DMan, it's people like you who make this forum into a place to be.

Still (call me stubborn, if you want :-) ), there are a couple of things which are not that obvious to me. I still don't understand why clicking on a menu item must lead to something. That's a matter of providing an option in the code, no? When I "simply" want a separation in my menu, a line (similar to what you see in your browser's menu items), i.e. a label without a link, my feeling is that this would be a small addition to the menu's module, with a lot of aesthetic or functional sense. Lists are ok, but lists with divisions are a lot easier to comprehend.

At this moment, my menu is about 20 items long. Too much, if you ask me, and it doesn't look nice. I feel I have 2 options:
- either make sub-groups of menu-items - but that would force me to indicate a path for the "clickable top item", which I don't want: I want the user to remain on the page where he is, I just want the submenu to unfold. Apparently, the only way out would be to go DHTML. Okay then, albeit with a * sigh *.
- or make divisions, lines in between groups of menu items - but if I understand you correctly, that doesn't seem to be possible: there is no such thing as a "separator" or a "line" possible. Again: *sigh*.

If I understood you correctly, this is the way it is. Well, in my opinion, an "inactive" menu element ought to be possible :-). Where is that form with the feature requests again...

Ludo

dman’s picture

In HTML, yes, a click on a link must do something. That something is visit a new location.

I understand a bit better what you are aiming for, if you will be satisfied with an inactive divider in the CMS menu builder, yes it is a reasonable request.

I tried making a menu item linking to '#' - which I'd interpret as 'current page' ... but that got escaped oddly. I think that would be the appropriate way of sneaking in this behaviour.

Feck. Why doesn't the menu allow me to put #anchors in?

Solution

OK, here you go, based on librettos solution for #anchors, plus my #null approach, pop this into your themes 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 $item['title'];
}

And you can now make unlinked divider menu items by linking them to just '#'
Lovely!
Try using them as menu sections and setting them 'always open' to get the visual effect (I think) you want.

You'll probably want to wrap a class around that last line for styling or something...

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

dman’s picture

Addition - for really simple unlabelled hr-type dividers, Something similar could be done.
the menu item can't be null, but it could be "-"

if ($item['title']=='-') return "<hr/>";

--- in the top of that same function.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

dman’s picture

I think it's a pretty tight solution, possibly worth including in my templates from now on - if not pushing into core.
... maybe just php snippets . ..

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

stewartstardust’s picture

As the subject says, just wrap this around your output and your menus are working as supposed with your styling intact!

Example


    return '<a href="#">'.$item['title'].'</a>';

That should do it for you..

modul’s picture

Ummm... Thanks, Stewartstardust, but where would I do this?? In which file?? I suppose in template.php? I'll give it a try there.

Thanks,

Ludo

stewartstardust’s picture

hi again,

Below is the complete example, with the last line edited to keep the styling:


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>';
}

bluefooz’s picture

dman, stewartstardust, ludootje thanks much for this code. It makes my day!

dman’s picture

Um, yes.
That amendment does do exactly what you say.
But the point here is that we deliberately don't want these spacer entries (subtitles) or spacers to appear as links, or be clickable. :)

I think to get styling tweaks, you'd be better to give it a non-href class and style that.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

stewartstardust’s picture

Sorry, misunderstanding on my part..

I just assumed that it was for the drop-down version of the nice_menus.. I can see now why you would avoid A HREF on vertical menus..

But anyways.. Just to clarify it.. Once again.. the amendment is only for users who wants the drop-down version of nice_menus with styling on their "placeholders"..

Does it make sense?? :P

Pardon my Danglish(Danish+English)

/jens

mlle.yotnottin’s picture

Thanks dman and stewartstardust! This is just what I needed for my site which DOES use nice-menus. Even if nobody else finds it useful it does exactly what I was looking for. Thanks!

gracearoha’s picture

This is great. Thanks for the code. It worked for me.
Now i am wondering how i can show the #linked menu item without the underline.
( I am using horizontal nice menus)

marcvangend’s picture

Hi,
I needed to do the same (create unlinked menu items) but in the context of primary and secondary links. I'd like to share with you how I did it.

Primary and secondary links are themed with theme_links (http://api.drupal.org/api/function/theme_links/5) so I copied the code to a theme override in my template.php.
Then I changed the next lines:

      if (isset($link['href'])) {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

into this:

      if (isset($link['href']) && $link['href'] != '#') {
        $output .= l($link['title'], $link['href'], $link['attributes'], $link['query'], $link['fragment'], FALSE, $html);
      }
      else if ($link['href'] == '#') {
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $link['attributes']['class'] .= ' menu-sub-header';
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }
      else if ($link['title']) {
        //Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }

As you can see, I check if not only the ['href'] value of $link is set, but also if it is not set to '#'. If $link['href'] equals '#', I add the class name 'menu-sub-header' to the $link['attributes']['class'] value for easier styling. Now I can add empty links by setting '#' as path.

By the way, the last elseif suggests that non-linking menu items are already a Drupal feature, but at the moment this is not true for the menu system.

dkabal’s picture

Marc:

Thanks for the brief code, I can't seem to get this code working (I even tried messing around a little), but maybe I'm using it wrong. I'm using the theme Garland, and what I'm after is placeholder top level primary links that expand to the second layer of the hierarchy if clicked:

Primary menu item A - Real path (i.e., goes to a node)
Submenu item 1
Submenu item 2
Primary menu item B - Placeholder (goes nowhere, except expands the subitems below)
Submenu item 3
Submenu item 4

I'm not a code expert, so any help to make this happen. Right now if I put the code above into the Garland theme (garland_theme_links) it just grays out the item and makes it unclickable (and kills the "triangle" for Garland above that menu item). Ideally, it would just open up the subitems as I describe above, and go nowhere else. I've seen numerous posts about NON-Primary menus, yours seems to be the only one that covers primary menus.

Thanks,
Dave

dman’s picture

A placeholder does nothing. It's just a label. That's what this exercise is about.
If you want it to be clickable, you need something else.
Like nicemenus.

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

marcvangend’s picture

Hi Dave,

As said, what you're trying to do is not what my code does. I think what you're looking for is the module DHTML menus (http://drupal.org/project/dhtml_menu). It adds javascript behaviour to your menu's to make the child items expandable/collapsible when the parent item is clicked.

Marc

scottrigby’s picture

Hi Marc,
I know this was a while ago, but I just tried to do this in Drupal 6, but am not quite getting it. Here's what I tried to do...

Changed the code from this:

function theme_links($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
        $class .= ' active';
      }
      $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';

      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}

To this:

function phptemplate_theme_links($links, $attributes = array('class' => 'links')) {
  $output = '';

  if (count($links) > 0) {
    $output = '<ul'. drupal_attributes($attributes) .'>';

    $num_links = count($links);
    $i = 1;

    foreach ($links as $key => $link) {
      $class = $key;

      // Add first, last and active classes to the list of links to help out themers.
      if ($i == 1) {
        $class .= ' first';
      }
      if ($i == $num_links) {
        $class .= ' last';
      }
      if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))) {
        $class .= ' active';
      }
      $output .= '<li'. drupal_attributes(array('class' => $class)) .'>';

      if (isset($link['href'])) {
        // Pass in $link as $options, they share the same keys.
        $output .= l($link['title'], $link['href'], $link);
      }
	  // Try to add marcvangend's solution from: http://drupal.org/node/128618#comment-726186
      else if ($link['href'] == '#') {
        if (!$html) {
          $link['title'] = check_plain($link['title']);
        }
        $link['attributes']['class'] .= ' menu-sub-header';
        $output .= '<span'. drupal_attributes($link['attributes']) .'>'. $link['title'] .'</span>';
      }
      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

      $i++;
      $output .= "</li>\n";
    }

    $output .= '</ul>';
  }

  return $output;
}

I still get the error message in Drupal 6

The path '' is either invalid or you do not have access to it.

Any idea what I might be doing wrong?

Scott Rigby
http://basekamp.com
http://PlausibleArtworlds.org

marcvangend’s picture

Scott,

I'm not sure if this method works in D6 at all; I didn't try it yet. Anyway, it seems that you have missed a line in the instructions that came with my code:

As you can see, I check if not only the ['href'] value of $link is set, but also if it is not set to '#'.

In other words, you also have to change this line:
if (isset($link['href'])) {
into:
if (isset($link['href']) && $link['href'] != '#') {

Please let us know if this solves the problem, it would be nice to know if this method works in D6 as well.

scottrigby’s picture

Hi Marc,
I now can't edit my post above for some reason, otherwise I'd do it... my php // comment (that includes the url) seems to be throwing off the code. I removed the offending comment...

I also added the line you recommend above, but no dice. I still get

The path '' is either invalid or you do not have access to it.

:(

Here is the code I'm using at the end of my template.php: http://drupalbin.com/2617

However, I noticed that from D5 to D6 api there's now this addition to that function:

      else if (!empty($link['title'])) {
        // Some links are actually not links, but we wrap these in <span> for adding title and class attributes
        if (empty($link['html'])) {
          $link['title'] = check_plain($link['title']);
        }
        $span_attributes = '';
        if (isset($link['attributes'])) {
          $span_attributes = drupal_attributes($link['attributes']);
        }
        $output .= '<span'. $span_attributes .'>'. $link['title'] .'</span>';
      }

Which sounds like it might be intended to do something similar to your solution... doesn't it? Maybe this could be modified here instead of adding an additional elseif statement above?

Scott Rigby
http://basekamp.com
http://PlausibleArtworlds.org

marcvangend’s picture

Probably, my code needs some adjustments for D6. Unfortunately I don't have time right now to look into it, but if you just take the original D6 code and try do again what I did with the D5 code, I think you should be able to figure it out.

allartk’s picture

Hi,

I think there are many solutions for this problem. Since a client requested I wrote one for D6.

I added the following code to my template.php

<?php
function phptemplate_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
    if($link['href'] == "<front>")    {
    return "<a href=\"#\">$link[title]</a>";
    }
    else
    {
      return l($link['title'], $link['href'], $link['localized_options']);
    }
}
?>

Which replaces all links to front into placeholders. Replace front with whatever you like.

giorgosk’s picture

But it would be nice to have
as an option (from core drupal I mean)
so that does not get abused like this

------
GiorgosK
Geoland Web development / web marketing

------
GiorgosK
Web Development

marcvangend’s picture

I totally agree. Although I'm not sure if it should be in core, it would be great to have a proper contributed module for this.

brei9000’s picture

I could not get this solution to work for me. I reset the cache under performance and still nothing. To clarify, people HAVE gotten this solution to work in Drupal 6 correct?

giorgosk’s picture

Yes its working for me on Drupal 6
include the code in your template.php

------
GiorgosK
Geoland Web development / web marketing

------
GiorgosK
Web Development

brei9000’s picture

This is what my code looks like in my template.php. I am using nice menus (though I tried it without, and it didn't work either). I put the code in my template.php file. Do I need to add something elsewhere? Maybe there is something obvious I'm missing.

function phptemplate_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
    if($link['href'] == "<empty>")    {
    return "<a href=\"#\">$link[title]</a>";
    }
    else
    {
      return l($link['title'], $link['href'], $link['localized_options']);
    }
}

I'm still getting the frustrating "The path '' is either invalid or you do not have access to it."

marcvangend’s picture

Did you actually enter <empty> as path, or did you leave the path field empty? I think you should do the first.

giorgosk’s picture

Clear your cache
and
use <front>

I don't think it can work with <empty>
(I think its an illegal parameter)

------
GiorgosK
Geoland Web development / web marketing

------
GiorgosK
Web Development

stoob’s picture

nice code. of course if a person doesn't want the place holder to be a link AT ALL just

<?php
function phptemplate_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
    if($link['href'] == "<front>")    {
    return $link[title];
    }
    else
    {
      return l($link['title'], $link['href'], $link['localized_options']);
    }
}
?>

Note that you should check the "Expanded" option if this placeholder is to have children in the menu

twod’s picture

If you'd like to keep <front> working normally, implement this in custom.module (or any other module you use for site-specific customization).

Then you can make your placeholder links point to <none> instead, as it's now a valid menu item. Using the page callback for this menu item, you could even add some tracking functionality so that in the unlikely event of someone landing on this page, you'll know where they came from.

Of course, you'd also need to change the hook_menu_item_link() examples to check for <none> instead of <front> as well.

/**
 * @file
 * Project specific customizations by *me*.
 */

/**
 * Implementation of hook_menu.
 *
 * This just adds a "null" menu router item for menu placeholder items.
 * All menu links pointing to "<none>" should be themed to render without an
 * actual <a> tag using hook_menu_item_link() in template.php.
 */
function custom_menu() {
  $items['<none>'] = array(
    'title' => 'NULL page',
    'page callback' => 'custom_null_page',
    'page arguments' => array(),
    'access arguments' => array('access content'),
    'description' => 'A custom null page',
    'type' => MENY_CALLBACK,
  );
  return $items;
}

/**
 * Callback for the "null" menu router item to display a wanrning message.
 */
function custom_null_page() {
  return 'THIS PAGE SHOULD NEVER BE SEEN!<br />Fix hook_menu_item_link() in template.php so links to this page are not rendered as actual links!';
}
kayograco’s picture

When at home, all my <front> links were .active, so I implemented this code and it worked nice. But now, as the placeholders links to #, they expand and collapse immediately in firefox.

nargonne’s picture

Instead of as the placeholder try a legal url such as http://example.com which already goes nowhere (sort of) and is acceptable by Drupal when creating the menu path

This way you avoid interfering with how Drupal normally uses

Fayna’s picture

this is the only solution that worked for me without interfering with how drupal normally works. thank you!!

function phptemplate_menu_item_link($link) {
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
    if($link['href'] == "http://placeholder.com")    {
    return "<a href=\"#\">$link[title]</a>";
    }
    else
    {
      return l($link['title'], $link['href'], $link['localized_options']);
    }
}
Prarthana’s picture

This works fine for me with Drupal 7 as well.
And no problems with the breadcrumbs too.

thanks a lot

arpita.2530’s picture

@ allartk you are great, this solved my problem... thanks a ton..

Rico Heart’s picture

Great! It works nicely.

I have three problems:

1)

The theme I use (az older version of Zen Classic) already has a 'function phptemplate_menu_item_link' function (in template-menus.php in the Zen root dir), and simply merging the code above either not works (if pasted after the original), or spoils the tab solution established.

This is not working:

function phptemplate_menu_item_link($item, $link_item) {
  // If an item is a LOCAL TASK, render it as a tab
  $tab = ($item['type'] & MENU_IS_LOCAL_TASK) ? TRUE : FALSE;
  return l(
    $tab ? '<span class="tab">'. check_plain($item['title']) .'</span>' : $item['title'],
    $link_item['path'],
    !empty($item['description']) ? array('title' => $item['description']) : array(),
    !empty($item['query']) ? $item['query'] : NULL,
    !empty($link_item['fragment']) ? $link_item['fragment'] : NULL,
    FALSE,
    $tab
  );
  // Non-clickable menu items
  if ($item['title']=='-') return '<hr />';
  $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 '<span class="nonlinkmenuitem">'.$item['title'].'</span>';
}

2)

My second problem is that I would like to clear the list-style bullet, but as Drupal puts the menu item in a line, I cannot style the line with the above php...
Is it doable?

3)

Third is that if using '-' in the title of a menu item, and being located in a sub-node, breadcrumb displays the hr.

Please help me solve at least the first problem!

UPDATE: I managed to create the same effect with only using extra menu blocks and custom css.

  #container .sidebar .block { margin: 0 0 1em 0;}  /* original with margin-bottom */
  #container .sidebar #block-menu-110, #container .sidebar #block-menu-235 { margin: 0 0 0 0; border-bottom: none; padding-bottom: 1px; } /* no margin-bottom, no border and smaller padding-bottom */
  #container .sidebar #block-menu-235, #container .sidebar #block-menu-234 { border-top: none; } /* eliminating the remaining borders */

jdsaward’s picture

I'm using Zen theme and have a sub-theme.

In my template file (in the sub-theme directory) I have added a slightly re-coded version of the function:

function zen_menu_item_link($item, $link_item) {	
	if ($link_item['path'] == "<none>") {
		return  '<span class="menu_placeholder">'.$item['title'].'</span>';
	} 
	else {
		$tab = ($item['type'] & MENU_IS_LOCAL_TASK) ? TRUE : FALSE;
		return l(
			$tab ? '<span class="tab">'. check_plain($item['title']) .'</span>' : $item['title'],
			$link_item['path'],
			!empty($item['description']) ? array('title' => $item['description']) : array(),
			!empty($item['query']) ? $item['query'] : NULL,
			!empty($link_item['fragment']) ? $link_item['fragment'] : NULL,
			FALSE,
			$tab
		);
	}	
}

I put it in my sub-theme directory and call it zen_menu_item_link rather than phptemplate_menu_item_link so that it over-rides the phptemplate_menu_item_link in the root of the zen theme.

Then I use <none> as the URL for menu items that I want to appear as text rather than a link.

Then I theme class menu_placeholder appropriately.

It works perfectly. I do find I need to clear the menu cache sometimes to see the changes as I code.

Rico Heart’s picture

Thanks JD!

I will not apply and try your solution yet, as I'm quite content with where I arrived with extra menus with custom css.
But it is bookmarked for future reference!

Thx again.

batigolix’s picture

hi, i like this approach

i added some code and changed yours a bit to created EMPTY placeholders, empty lines that divide the menu in pieces

i use the a zen sub theme so my functions are called zen_menu_item and zen_menu_item_link

i removed the list bullet of the standard class=leaf li list item by naming it "autumn-leaf" and adding the css code:

.autumn-leaf {
  list-style: none;
}

so this goes into my template.php in sites/all/themes/zen/NAMEOFTHETEMPLATE:

/* for empty placeholders */

function NAMEOFTHETEMPLATE_menu_item($mid, $children = '', $leaf = TRUE) {
$item = menu_get_item($mid);

if ($item['title'] == "<none>") {
return '<li class="autumn-leaf">'. menu_item_link($mid) . $children ."</li>\n";
}
else {
  return '<li class="'. ($leaf ? 'leaf' : ($children ? 'expanded' : 'collapsed')) .'">'. menu_item_link($mid) . $children ."</li>\n";
}
}

function NAMEOFTHETEMPLATE_menu_item_link($item, $link_item) {
if ($link_item['title'] == "<none>") {
return  '<span class="menu_divider">&nbsp;</span>';
}
elseif ($link_item['path'] == "<none>") {
return  '<span class="menu_placeholder">'.$item['title'].'</span>';
}
else {
$tab = ($item['type'] & MENU_IS_LOCAL_TASK) ? TRUE : FALSE;
return l(
$tab ? '<span class="tab">'. check_plain($item['title']) .'</span>' : $item['title'],
$link_item['path'],
!empty($item['description']) ? array('title' => $item['description']) : array(),
!empty($item['query']) ? $item['query'] : NULL,
!empty($link_item['fragment']) ? $link_item['fragment'] : NULL,
FALSE,
$tab
);
}
}
bharanikumariyerphp’s picture

Hi dears,

I know for new problem, we have to create the new thread,

But i posted lot of quries but no response from our group , i dont know what is reason,

So one doubt from my side,that is i am not sure am correctly creating new thread or not,

Any one plz tell how to post the new thread,

In the forum combo, which category we have to choose,

Plz Response me,

Thanks in advance

Regards
B.S.Bharani kumar

modul’s picture

Yep, this must have been a very tough thing to answer, apparently... Verrrrry strange indeed: I was simply (?) asking
- how to put a line or a separator in my menu, delineating parts of my menu which belong together,
- and/or how to put an item in my menu which only serves as a "placeholder" for other things, i.e. which unfolds upon clicking to show the things on a lower level, but which does not lead to any node itself.

Is this really that difficult to accomplish (preferably without any additional module) ??

Ludo

drupaldooer’s picture

basically, i have a menu with the following items: "home", "site map", and "content" , displayed horizontally.

I would like them to appear like this: "home | site map | content"

, with "|" spacers in between... how can i do this?

paulgibbs’s picture

My thoughts exactly...you'd think this would have been a rather common scenario. Odd that you'd have to insert custom code into your template to make it work. Maybe in v. 6 there will be some a "beginner method" for menu creation...? And some sort of menu building improvement to make menus without needing to know that you have to type in "?q=node/..."?

This CMS is excellent---just needs another couple stages of refinement on the simplicity front to make it less intimidating to the new user. I couldn't believe my eyes when the tutorial, which had taken me relatively easily through the beginning steps of setting up a site, arrived at the menu-building stage and basically dumped you with a sort of "sorry buster, this one's just plain obscure--good luck".

ticomp’s picture

Hi! I'm having a similar probnlema but I still don't want to add a false link dinving. My objective is put labels like header(h2) 'cause I want they themed just like the name of the menu above.
For figuring out what I want just put the Who's Online block available on any sidebar.
When you look at the first label "who's online" you see that is an h2 type
and the label Online users below are h1 or h2 I think.

I tried use two menus (two blocks) and place right below but I'm having a problem with IE6 that the first block (I tested with primary links on the right sidebar) in 800 x600 resolution gets a freaking width with a lower value than the others.

In firefox they got the same width and runs very well.

Regards,
Thiago Manhães

femrich’s picture

If I can chime in, when I look at Drupal out of the box, I see in the navigation menu several items that serve as both top-level menus *and* as links to pages containing more explanation about those menu items:

i.e. if I click "create content" the menu expands to show links for the various content items available, and the linked page offers a list of those same items with more explanatory detail on what those items are.

This is a format that appears frequently in the default navigation menu and, I think, logically there should be a relatively easy way to create something similar for added menu items. In fact, this seems so obvious that I was assuming it could be done easily and I had just not yet figured out how.

The solutions offered here seem too complex. Isn't there a way to do this in core?

I guess the key here is figuring out how it is that the nodes linked to "create content" or "admin" seem to be automatically updated whenever a new menu item is placed within those menus. That's the kind of thing I would like to be able to create within my existing menus. Any tips on how to do this?

jefbak2’s picture

I just need a Menu title PROJECTS
with clients in the submenu like NBC and ABC for instance
Then I use views to add menu items under NBC or ABC

I then have a CONTENT TYPE for submitting an NBC and ABC report
Then I use VIEWS to add doucments NBC or ABC submenus

But I have to give menu PROJECTS some kind of node/path for it to show up. Of couse node/add would not work and does not work.

This is a vertical right side bar menu that I just want to expand downward to show submenus...

trevorulyatt’s picture

I haven't read all the replies so this may be duplicating but usually putting a hash # in the URL field should do the trick.

vann’s picture

having a placeholder menu item is a common need. yet in drupal, this requires a custom hack in php. that's the essence of drupal in a nutshell: a powerful system that overlooks the obvious, like the bumbling professor who can't remember where his glasses are.

using a "hash" (#) in the "path" field of a menu item does not work in drupal 6.0. neither does javascript:void(0). neither does inserting <none>, which was a theme tip from drupal 5.x! you'd think this would be a 1.0 feature, not a hack mentioned for 5.0, that's still not integrated into 6.0.

it's dumbfounding and frustrating. i'm sure i could hack something to work, and then when upgrades overwrite it, role the hack in again. brilliant.

eric_drupal’s picture

isn't there a way to do this, anyone ?
im using drupal 6, would be soooo helpful if someone new now to make a placeholder menu item

summit’s picture

Subscribing, greetings, Martijn

jwm4’s picture

I agree with Eric and whoever he agreed with....how can Drupal make something that can be easily done with css/html so difficult. Is there no solution to this problem for Drupal 6.x? Submenutree (referenced as a solution below) does not appear to be Drupal 6.x ready.

Martin Möhwald’s picture

That would be really helpful, indeed.

scottrigby’s picture

Hope I'm not giving false hope, but based on the issue queue, it seems Submenutree 6.x-1.3 is ready and resolves this issue. I'm testing now to check it out

Scott Rigby
http://basekamp.com
http://PlausibleArtworlds.org

scottrigby’s picture

Yep – submenutree works really well :) and is pretty fantastic actually...

BUT... it doesn't help with the placeholder menu items (menu items which are not links themselves). Unlike some of the requests on this page, I don't want to have these placeholders expand (because dhtml_menu works wonders for that). But I want to keep the menu items expanded always (which I can do using core menu), but I just want the menu items to not be links themselves (using one of the # solutions above)

However, I can not seem to sort out how the theme menu override offered for D5 could translate to D6 because of api changes - see my comment above .

If any of y'all could help who are more familiar with the overriding the api than I am, you'd have at least +1 more fan out there :)

Scott Rigby
http://basekamp.com
http://PlausibleArtworlds.org

DrupalBone’s picture

I've used submenutree for this purpose on my site. It will create a list of the menu items that are the direct children of the menu item you are at, and you can create a title for this list that could say "check these" or what have you. You can take this list and title, and either put it in the main content of that node that is the parent item, or put it in a block.

Of course, I create this parent item as a node, but its only contents are the list of its direct children from the menu system. I always leave the menu breadcrumb in place so that people can navigate up the directory if they choose to and that makes it very usable.

I even convinced the module maintainer to allow us to use the same system for sibling items, which would be a sister item to the current node, which would create a list of all siblings in a separate block. This is very useful for navigation.

Check it out because it is a high quality module, it has great code.

dman’s picture

Sounds handy.
Sorta like splitmenu (I think) does ... but more versatile

.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/

DrupalBone’s picture

And I now realize that I didn't really point out just how versatile it is. Submenutree lets you configure both the title of this list of menu items and whether it is displayed in content or as a block PER EACH NODE that it will show up on. The flexibility of such a thing is amazing since you don't have to have a generalized title that applies to every list, but a specific title for each list, and you can put that list wherever you want it to be on each node.

I'm starting to think of new ways this functionality can be extended since I really think this module has some seriously untapped potential.

codesmith’s picture

But to answer the original question, possible to use this menu module to have a menu link with *no* link to a page. Just expands/collapses the menu?

marcvangend’s picture

You can do that with the DHTML menu module, http://drupal.org/project/dhtml_menu

modul’s picture

What a strange feeling... About 1 year and 3 months ago, I asked the question which started this thread: how to make a menu item without having to link it to some path, i.e. I wanted a menu item which, upon clicking, would either do nothing (in which case the menu item would just be a placeholder, a division like a horizontal line or so), or which would open up underlying menu items (in which case the menu item would just be active in the menu itself). I knew there were modules which would take care of this (such as DHTML Menus), but my whole point was why on earth something simple (and essential...) like a dividing line was so hard to accomplish in Drupal itself, without having to use a whole module just for a simple dividing line.

Many many replies were formulated. And today, one year and three months after this thread was born, there is the same reply again: use DHTML Menu :-) :-) :-) :-) Come on guys, a whole module just for one measly line??? Nah.

marcvangend’s picture

If all you need is a divider, this thread has documented some good ways to do it. I think we have proven that you do not need a whole module for it.
If you're looking for expand/collapse behaviour, well scripted, with graceful degradation, cookies to save the state and more nifty features... IMHO, DHTML_menu is well worth it's KB's.

dman’s picture

I have a client with an extremely simple request - they want to be able to drag an image out of their desktop photoshop application and place it into a spot on a page in the CMS.
Obvious. Simple. Essential.

Why on earth could that be difficult?

If they are an intelligent client, they'll understand me if I say that's actually trickier than it looks, and learn about the work-around that takes three steps instead of one. Because they actually want to get a result.

Or ... they could refuse to listen to the alternatives and declare that it's simple and obvious, and it's my fault for not just doing what they want.

.dan.

bendshead’s picture

The carrot is out of the bag...

http://drupal.org/node/344771

waynedrupal’s picture

subscribe

OnlineWD™’s picture

Simple solution for DHTM menu, delete from dhtml_menu.js ..

    if (effects.clone) {
      var ul = $(li).find('ul:first');
      if (ul.length) {
        $(li).find('a:first').clone().prependTo(ul).wrap('<li class="leaf fake-leaf"></li>');
      }
    }

I too am a new comer, learned how to use taxonomy to create categories and then thougt it was strange that a menu item must have an URL. It's very strange in website design for a menu item to expand and link at the same time, logic dictates it's not necessary because the sub menu items describe the category. Usually it's either a single link to a page or an expanding menu item, unusual to have both at the same time however I can see uses for it for example more detailed description of a catergory or alternate (more attractive) means of decription.

giorgosk’s picture

Check this out
http://drupal.org/project/special_menu_items
it promises to give such a solution

placeholder
and
nolink
items for menus

------
GiorgosK
Web Development

smrati’s picture

hey guys , i am confused regarding the expandable menus.

I want to create menu that will show only Class names and when a particular class is clicked, all the sub headings should appear and on further clicking the subheadings it will take us to a different page . all sub menus should get open on the same page. Please help me how should I proceed and where should I incorporate the code ?

Please guys help me.... I am new to Drupal and deadline to submit my project is quite close.

Any kind of help shall be appreciated.

Thanks

marcvangend’s picture

smrati’s picture

Thanks buddy,

I implemented it and it is working great. Thanks for replying .Now it seems that the project can be completed on time .

I have one more problem. Rather than embedding my video as an attachment on a page type ,i want the video to play directly when the menu link is clicked. How it can be done in drupal ?

Please reply as soon a possible.

Smrati

marcvangend’s picture

Please keep forum threads on topic. This is a completely different subject, I suggest that you open a new thread for this if you can't find the answer by searching (ie. http://drupalmodules.com/search/node/video+category%3A24).

anrikun’s picture

marcvangend’s picture

That's funny, I just posted a patch implementing exactly the same functionality in Special menu items module. See http://drupal.org/node/515736.

anrikun’s picture

Funny indeed, the very same day! :-)

JohnBentley’s picture

Is there a settled and new method for achieving this which makes all the hacks in this thread redundant?

giorgosk’s picture

read the thread - more than one solutions exist already

------
GiorgosK
Web Development

JohnBentley’s picture

Thanks for the prompt. I may well be missing it, but I just don't see the answer to the original problem.

  • In Create unlinked menu items / dividers. dman showed how to override your theme's template.php and, in principle, construct different menu items based on different inputs. However, this doesn't work on 6.x.
  • In for D6 you mirght try this allartk showed how to do the above in 6.x (with phptemplate_menu_item_link($link) ..) but used <front> has the path designator in menu items. However, you may want to use <front> to refer to the front page, rather than no page.
  • In Avoiding in D6 TwoD showed how to add some code to custom.module to setup <none>, rather than <front>, as a path designator in menu items. However, now clicking on your parent menu item doesn't reveal the children.
  • In DHTML menus marcvangend refers to DHTML Menu which does a fine job of expanding children under a parent. However, it also includes, as the first child a copy of the parent item.
  • In Simple solution for DHTML OnlineWD shows how to remove the instance of the parent item repeated as the first child with a hack. However, that does it for all parent items, including those on the Admin menu. Furthermore, if the DHTML menu module is updated then the hack is removed.
  • http://drupal.org/project/menu_firstchild, although potentially a good workaround, does not do what the original post requests. That is, simply expand the children under a parent without jumping to any page.
  • In Check this Giorgosk, your good self, refers to http://drupal.org/project/special_menu_items. However, the placeholder does not contain a link and so will work only with suckerfish type menus, rather than a DHTML menu. If I'm not mistaken.

So, unless I've missed something, perhaps the next step would be to make DHTML Menu apply only to those Parent Menu Items marked with the path designator <none> (using TwoD's technique).

JohnBentley’s picture

I missed something very basic. DHTML Menu is configurable under site configuration. That solves everything.

For others in my position (that have yet to come) I'll shortly do a full post that explicitly goes through all the steps to solve the original problem.

halefx’s picture

I actually am in your position, so I'm interested in how you solved this problem. I have:

Level 1 nolink
  Level 2 nolink
    Level 3 <firstchild>
      Level 4 node

If I use Special Menu Items to create the level 1/2 parent menu items, the parents are not clickable/expandable in DHTML Menu and I can't access level 3/4 at all. If I use Menu FirstChild to create the level 1/2/3 parents, the link for level 3 actually displays as <firstchild>, the active trail is broken, and functionality breaks (clicking goes to example.com/<firstchild> instead of expanding). Am I missing something? TIA

anrikun’s picture

You have to choose between Special Menu Items and Menu Firstchild:
if you choose Menu Firstchild, you have to use it for level 1 and level 2 too:

Level 1 <firstchild>
  Level 2 <firstchild>
    Level 3 <firstchild>
      Level 4 node
halefx’s picture

Doesn't work. If I set all three parents to <firstchild>, the link for level 3 actually displays as example.com/<firstchild>, the active trail is broken, and functionality breaks (clicking goes to example.com/<firstchild> instead of expanding).

anrikun’s picture

Have you disabled/uninstalled Special Menu Items?

halefx’s picture

Disabled and uninstalled SMI. Still happens. I can now be more specific as to when the bug occurs, though. If it's a third level link that is not a descendant of the last first level link and it is not the last child of its level2 parent, it breaks.

Link1
  Link2
    Link3*
      Node1
    Link4*
      Node2
    Link5
      Node3
Link6
  Link7
    Link8
      Node4
    Link9
      Node5

The links marked with asterisks go to example.com/<firstchild> instead of the actual first child's node link. WTF, right?

anrikun’s picture

Please open an issue in Menu Firstchild about this.

pedroportella’s picture

By Dan Morrison | http://coders.co.nz/

// your path under Menu settings need to be "<front>#none"
function theme_menu_item_link($link) {
	
  if (empty($link['localized_options'])) {
    $link['localized_options'] = array();
  }
	
  if($link['localized_options']['fragment'] == 'none')
    return $link['title'];
  else
    return l($link['title'], $link['href'], $link['localized_options']);
}
trevorulyatt’s picture

I know this problem well and have sought a simple solution on many occasions. Like others I have usually resorted to the DHTML module but it doesn't really provide a good solution for the issue raised. As I was reading through the many replies I suddenly thought, why not simply use the 'add menu' capability to add a new menu block for each cluster of nav links you require?? Each new menu block can be named appropriately. OK, maybe not tres elegant but I think that might just do the trick!
Gotta dash and go try it out!!
Regards to all,
Trevor Ulyatt
www.nzwebdesigners.com

stoob’s picture

marleo’s picture

YMMV with this module: http://drupal.org/node/507758

amitgarg’s picture

Hi,

put the below line in path & put your desire title

http://#

Thanks,
Amit Garg
amit@highpixel.in
http://highpixel.in

tami.allen’s picture

This solved my placeholder issue. So simple! Thank you!

Update: this only works in Chrome. Firefox, IE9 and Safari still give an invalid path error. Any help would be greatly appreciated!

marcvangend’s picture

It has been mentioned before in this thread, but did you try the Special Menu Items module?

tami.allen’s picture

My solution was to switch to using a Suckerfish menu and adding Special Menu Items. In the Special Menu Items module configuration I changed the html tag for "nolink" to < a href ="#"> (without spaces) and that took care of the tabbed styling problem that the default < span > gives. Now I have a nice drop down menu with children and the parent tabs are placeholders.

amontero’s picture

strands’s picture

@tammi.allen from http://drupal.org/node/128618#comment-6072344
Smart - thank you ...

wilderman’s picture

I support a non-profit website (Drupal 7). They have been asking for non-clickable menu items for several years. The module special_menu_items is the perfect solution.