Dynamic section-specific submenu I have a problem that's driving me bananas on Drupal 7.

My need is very simple. I have a site with a bunch of communities with URLs like

http://domain.example/community/communityname

All of these communities have similar structures with pages like "learning", "blog" etc. which are at URLs such as

http://domain.example/community/communityname/learning

I need to create a navigation menu for each of these communities without actually creating a separate menu item for each. How can this be achieved?

I tried doing this with hook_menu and even after 3 hours of relentless googling and fiddling about I just can't seem to get this working.

Any help is much appreciated.

Here's my non-working code:

function mymodule_menu(){
    $items = array();
    $items['community/%mymodule_arg/learning'] = array(
        'title' =&gt; 'Learning',
        'page callback' =&gt; 'mymodule_view_page',
        'page arguments' =&gt; array(1), 
        'menu_name' =&gt; 'menu-community-menu',
        'type' =&gt; MENU_NORMAL_ITEM,
        'access callback'=&gt;TRUE
    );
    return $items;
}

function mymodule_arg_to_arg($arg) {
    return (empty($arg) || $arg == '%') ? "community-a" : $arg;
}

function mymodule_view_page($context) {
    return drupal_goto("community/" . $context . "/learning");
}


If I replace the wildcard from the items array key and replace it with a static string, the code works. Also if I just return a string from mymodule_arg_to_arg() it works. But I just can't seem to make it dynamic.
You seem to me trying to make it more complicated as necessary. You can simply use the arg function http://api.drupal.org/api/drupal/includes--bootstrap.inc/function/arg/7

in your example domain http://domain.example/community/communityname

arg(0) = community;

arg(1) = communityname;

so why not just use arg(0) and arg(1) in your dynamic link url