1

I am trying to create a menu item that loads a view mode that calls the callback function with the path alias.

$items['node/%/%'] = array(
  'page callback' => '_node_view_load',
  'page arguments' => array(1, 2),
  'access callback' => TRUE,
  'type' => MENU_CALLBACK
 );

function _node_view_load($node_id, $view_mode = 'default') {
  return drupal_render(node_view(node_load($node_id), $view_mode));
}

This works if you go to /node/%/view_mode. However, it does not work if you got to /alias/view_mode. I get page not found. Is there a way to bind menu items to path aliases?

  • I would rather use node/%node/%, and the call to node_load() would not be necessary; the last % is a catch-all, and it could match paths already defined by other modules. – kiamlaluno Apr 28 '11 at 16:19
  • How did you create the alias? If "test-page" is the alias for "/node/1," when you visit example.com/test-page you will see the content of example.com/node/1, which means the callback associated with "/node/%node" is invoked. – kiamlaluno Apr 28 '11 at 18:04
1

You'd have to extend the pathauto system to handle your specific pattern, like it does for node/x/feed items.

0

I think that the Sub-path URL Aliases module will do what you want.

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.