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

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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