0

I simply want a menu item which scans the url, grabs the second argument, and plugs it into the second wildcard location of the new menu item it's creating.

So if the URL is: http://drupal.org/contenttype1/johndoe (johndoe = 2nd argument)

the menu item displayed will be: http://drupal.org/contenttype2/johndoe (johndoe = wildcard location)

So far, based upon a few forum, I've sketched out the following code, which is clearly incomplete, and it is doing nothing right now.

Basically, I just want this menu item to link to an existing page mysite.com/[coach name]/page. I'm using clean URLs by the way.

        <?php
    function coachmenu_menu() {
      $items = array();

      $items['%/page'] = array(
        'title' => 'Coach Page',
        'page callback' => 'coachpagelink',
        'page arguments' => array('0'),
        'access arguments' => array('access content'),
        'type' => MENU_NORMAL_ITEM,
        'menu_name'=>"menu-coach-menu",
      );
        return $items;
    }

    function coachpagelink($wildcard) {
        return $wildcard;
    }

Any ideas on what I can do?

2 Answers 2

2

Your code is fine except for a detail. The correct menu definition is the following one.

$items['%/page'] = array(
  'title' => 'Coach Page',
  'page callback' => 'coachpagelink',
  'page arguments' => array(0),  // Use an integer, not a string.
  'access arguments' => array('access content'),
  'type' => MENU_NORMAL_ITEM,
  'menu_name'=>"menu-coach-menu",
);

If you use a string in the page arguments, the page callback is not receiving part of the URL, but that string. In your case, the page callback is always receiving '0' as argument, even when the page callback is invoked for example.com/jhondoe/page.

0

AFAIK, wildcards cannot be used as a first argument. See "Simple Wildcards" under "Wildcards in Paths" section in hook_menu() documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.