1

Reading hook_menu it says this:

"title": Required. The untranslated title of the menu item.

"title callback": Function to generate the title; defaults to t(). If you require only the raw string to be output, set this to FALSE.

"title arguments": Arguments to send to t() or your custom callback, with path component substitution as described above.

So how to use it? Right now i have this

function custom_gmap_neo_menu(){
    $item = array();

    $item['custom_gmap_neo/%/%/%'] = array( // hotel/origin/destination
        'title' => 'Get directions to @hotel',
        'title arguments' => array(1),
        'page callback' => 'custom_gmap_neo_show',
        'page arguments' => array(1,2,3),
        'access callback' => TRUE,
    );

    return $item;
}

function custom_gmap_neo_show($hotel, $origin, $destination){
    dpm($hotel);
    dpm($origin);
    dpm($destination);

    return '';
}

So knowing that default function for title callback is t() how to actually pass the @total wildcard to the t() function?

2

When you define title arguments as an array, each array element will be passed as arguments in that sequence.

Now you have title arguments defined as array(1), which means the actual call would mimic t('something') if the URL path was custom_gmap_neo/something/something_else/something_else_1.

If you want to call t() function as t('Get directions to @hotel', array('@hotel' => 'something')), you need to define your own title callback, because automatic integer to path argument translations only happen in the root level array elements.

<?php 
function custom_gmap_neo_menu(){
    $item = array();

    $item['custom_gmap_neo/%/%/%'] = array( // hotel/origin/destination
        'title arguments' => array(1),
        'title callback' => 'custom_gmap_neo_get_map_title'
        'page callback' => 'custom_gmap_neo_show',
        'page arguments' => array(1,2,3),
        'access callback' => TRUE,
    );

    return $item;
}

function custom_gmap_neo_show($hotel, $origin, $destination){
    dpm($hotel);
    dpm($origin);
    dpm($destination);

    return '';
}

function custom_gmap_neo_get_map_title($hotel) {
  return t('Get directions to @hotel', array(
      '@hotel' => $hotel
    ));
}
?>

However, if your first URL argument (hotel) is a node, consider using %node as the path wildcard, because it can load the node for you, and handles page not found errors automatically if node_load returns an empty result. Otherwise you will have to call node_load twice. node_load caches results, but there are many loader functions that do not cache results.

  • hmm i see it clear now, thank you. hotel it is not a node it is just a string – Gianni Di Falco Mar 5 '15 at 15:05

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.