Using tokens in a menu link

flickerfly's picture

I have a menu item that I'd like to make different for each user. It's an internal page that accepts &_GET in the URL.

I'm thinking I could skip the user past entering this information in manually by providing the url like http://site.com/?user=loggedinuser&target=somepage. Could I fill this username with the drupal username using a token or are they just not available in the context of menu entries?

How else could I solve this if not with tokens?

Groups:
Login to post comments

I'm trying to do exactly the same thing

ebrittwebb's picture
ebrittwebb - Tue, 2008-11-04 22:48

I'm trying to do exactly the same thing. Would love to see a solution for this!


Did you figure this out?

arilikeairy's picture
arilikeairy - Wed, 2008-12-03 22:45

I'm trying to do the same thing and haven't figured it out yet, did either of you?


Similar solution implemented

develCuy's picture
develCuy - Thu, 2009-01-01 00:52

Similar solution implemented by menu_token.module.

Happy New Year!

--
develCuy's fruits
(3 John 1:2) Dear friend, I pray that you may enjoy good health and that all may go well with you, even as your soul is getting along well.


Excellent

ebrittwebb's picture
ebrittwebb - Tue, 2009-01-06 00:44

Look forward to trying it out, but there aren't any downloads available yet. When will they be?

Also, it appears right now you have only a 5.x branch. What about 6.x?


Downloads available now, D6

develCuy's picture
develCuy - Tue, 2009-01-06 05:04

Downloads available now, D6 release not in plans but patches are welcome.

--
develCuy's fruits
(3 John 1:2) Dear friend, I pray that you may enjoy good health and that all may go well with you, even as your soul is getting along well.


Has anybody figured this out

tms8707056 - Sat, 2009-01-31 22:09

Has anybody figured this out for 6.x?


Use a redirect page

zeedaam - Mon, 2009-02-23 00:37

I needed to do this on a site I'm building too. So I created a simple redirect.php page.

<?php
require_once './includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
global
$user;
echo
"<meta http-equiv='refresh' content='0;url=user/" . $user->uid . "/edit'>";
?>

For example I made a link in the nav menu that would take the user directly to their user/edit page. I pointed the menu item to my redirect.php and it sent them to an evaluated redirected url. It's pretty fast and seamless too. Hope this helps until some makes this for Drupal 6.


I'm looking for the same

Danny_Joris@dru... - Thu, 2009-05-21 09:21

I'm looking for the same thing in D6. I would love to show a menu title as a token. In my case i want to show the user name.


I can help

NancyDru's picture
NancyDru - Thu, 2009-05-21 14:15

The Real Name module can provide that link in the Nav menu title.

Nancy Dru


Me Aliases

heartsutra's picture
heartsutra - Tue, 2009-07-14 16:34

Try the me aliases module.


function

shaggy-gdo's picture
shaggy-gdo - Fri, 2009-08-07 11:59


function phptemplate_menu_item_link($link)
{
if (empty($link['localized_options'])) {
$link['localized_options'] = array();
}
//Make all external Links "_blank"
if ( isset($link['href']) && substr($link['href'], 0, 4) == 'http' )
{
$link['localized_options']['attributes']['target'] = '_blank';
}
//Use Tokens
if ( module_exists('token') )
{
$link['href'] = token_replace( $link['href'],'global' );
$link['title'] = token_replace( $link['title'],'global' );
}
return l($link['title'], $link['href'], $link['localized_options']);
}

Erik


Thoughts?

rjbrown99 - Tue, 2009-08-11 04:04

I'm also interested in this (for Drupal 6), but not just for tokens. I'm just trying to pass an argument into a URL based on a view page path that uses an argument. For example, a view path of /documents/% where % is the user's userID. I can then browse to a URL of www.mysite.com/documents/userID to see the view of that user's documents. Now I want that view in a menu which is where I run into the challenge since the path is different per URL. The menu will only appear on the page of the user that 'owns' that view, so I can get the argument to pass to the menu without a hitch. But how do I pass it to the menu? My problem is that Drupal's menuing system does not seem to accept /documents/% as a path and instead kicks back an invalid path error when I try to add that as a menu item in Admin -> Site Building -> Menus.

The Me module won't work in this case since it deals with the logged in user, and I need this to work for any userID that is passed as an argument in the URL. I looked at Path Redirect but this also didn't seem like the right fit. Menu token would work great by pulling a userID token, but it's D5 only so it's not an option for me. That brought me to this page as well as this comment: http://drupal.org/node/201848#comment-761771

Unfortunately, menu_item_link has been removed in D6 so that isn't an option either.

Does anyone happen to have a suggestion in this case? What's the preferred approach to passing a dynamic argument to a Drupal menu in D6?

FWIW, I have full root access to my server with no limitations whatsoever in terms of installing modules, modifying themes, changing configs, etc.


same problem here

tan1772 - Wed, 2009-10-28 15:11

anyone figured out a way?

alan t


+1 on this.

doublejosh's picture
doublejosh - Wed, 2009-11-04 07:15

+1 on this.


Me three

rubyji's picture
rubyji - Fri, 2009-11-06 04:30

This should be straighforward! If I can make a view with an argument in the URL, I should be able to make a menu item to point to that view.

Suggestions appreciated...


I have the following in a

malc_b - Sun, 2009-11-08 16:44

I have the following in a module for all my custom functions (D6 BTW)

function mymodule_menu_link_alter(&$item, $menu) {
  if (substr($item['link_path'],0,1) == ':') {
    $item['options']['alter'] = TRUE;
  }
}

function mymodule_translated_menu_link_alter(&$item, $map) {
  global $user;
 
  if (substr($item['link_path'],0,1) == ':') {
    $item['href'] = substr($item['link_path'],1).'/'.$user->uid;
  }
}

Then the menu I put something like :blog/user . This changes to blog/user/33 for user 33.

The : at the beginning is to fool the menu it to believing it is an external link so it doesn't check it at save time. At run time the translation strips that and adds the current user id. Of course you can expand the processing to change an end token and replace that but since I just want the user id I don't bother.

Of course this only works for D6 menu. href links in the code have to be constructed with php.