Search code examples
drupalmoduledrupal-7hook-menu

Wildcard Page Argument in hook_menu() not working


I'm trying to create a pagination type menu item that would allow the user to see older/newer content. The wildcard would represent the multiplier that would set the range from which the content is culled. This is the array created within my hook_menu() implementation:

$items['cars/%'] = array(
    'title' => 'cars',
    'page callback' => 'cars_car_view',
    'page arguments' => 'page',
    'access callback' => TRUE,
);

and this is my page callback function:

function cars_car_view($page) {
    print $page;

    // Code
}

But when I print the $page variable, only "cars" is printed, rather than the number. I've read through the documentation on hook_menu, but can't seem to figure out what I'm doing wrong or what I should be doing instead. Any help?


Solution

  • You have to use array in page arguments. array(0) refers to cars array(1) refers to wildcard

    $items['cars/%'] = array(
        'title' => 'cars',
        'page callback' => 'cars_car_view',
        'page arguments' => array(1),
        'access callback' => TRUE,
    );