3

How can I have the page argument appear in the page title?

    $items['path/path/%'] = array(
    'title'            => t('Dynamic Title %1'),
    'page callback'    => 'pagecallback',
    'page arguments' => array(2),
     'type'             => MENU_CALLBACK,
    'access arguments' => array('access content'),
  );

Is there some kind of text replacement or something you can use in there, or is what I'm asking impossible?

4

You can use a title callback function along with title arguments:

$items['path/path/%'] = array(
  'title callback' => 'MYMODULE_page_title',
  'title arguments' => array(2),
  'page callback'    => 'pagecallback',
  'page arguments' => array(2),
  'type'             => MENU_CALLBACK,
  'access arguments' => array('access content'),
);

function MYMODULE_page_title($arg) {
  return t('Arg is: @arg', array('@arg' => $arg));
}

The default title callback is t(), so if you just need the argument to be passed straight through as the title you can get away with just using title arguments.

See hook_menu() for more details.

  • Perfect thank you, I couldn't find anything like this in the drupal docs but I didn't expect there to be a callback for the title. – Daniel Waters Nov 1 '13 at 16:17
  • 1
    @DanielWaters, If you do not want a callback for title, then you can use drupal_set_title function in your pagecallback function. – Jayendra Kainthola Nov 1 '13 at 16:48

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.