Ben
Ben

Reputation: 927

Create dynamic link in drupal

Could anyone tell me how to create a dynamic link in drupal?

I want to create a link to a group membership list. I have created the view with the argument. How do I create the menu item link to the view? It will be different depending on the group.

Thanks

Upvotes: 0

Views: 2122

Answers (3)

Shiro
Shiro

Reputation: 851

I create a redirect link for such situations. For example, if I want a menu link to direct the user to their user edit page, I will implement hook_menu() as follows:

function my_module_menu()
{
  $menu['user/cp'] = array
  (
    'title' => 'User Control Panel',
    'page callback' => 'user_cp_redirect_page',
    'access callback' => 'user_is_logged_in',
    'type' => MENU_CALLBACK,
  );

  return $menu;
}

Then, I set the page callback to look like this:

function user_cp_redirect_page()
{
  global $user;

  drupal_goto('user/' . $user->uid . '/edit');
}

Upvotes: 1

bkildow
bkildow

Reputation: 5153

It sounds like you may need to use views arguments to filter your results if you are pulling different "groups" based on a single view. I would start here to learn more about views arguments: http://drupal.org/node/54455, if this is indeed what you are trying to accomplish.

EDIT:

I guess it would help if I read the question fully. It sounds like you are already using arguments for your view. In this case you already have created dynamic links to your page. Try putting the arguments for each "group" at the end of the URL. For example if created a page display with a path news, you can pass the argument by appending it at the end of the URL. So, if you created an argument using "Node:Created Year" you could then filter this content by putting something like example.com/news/2009 to access only the nodes that were created in 2009. What you pass is dependent on the type of argument you have created.

Upvotes: 0

user113292
user113292

Reputation:

In short, you can't. Drupal's menu system caches the entire menu: menu items can't appear differently for different users (although you can set access permissions for them). If you want menu items to appear, you have to either register them in hook_menu() (which is only called when the menu is rebuilt), or you have to add them manually in Menu administration.

The handbook page on the Menu system provides more information about this.

However, you can create a fake menu using a block display in your view and the HTML list row style. This is useful if you wanted to have a category listing block, outside the main menu structure.

Upvotes: 0

Related Questions