hook_menu - setting a variable to use in page.tpl.php I know how to use hook_preprocess_page() to add/change variables for use in page.tpl.php. For nodes, you can use menu_get_object() to load the current node and process it from there. 

How do I do this for a page I've created using hook_menu()? I've tried printing out all the $variables but there is nothing much I can identify this page with, apart from the 'theme_suggestions' which seems a bit flaky. Using arg(0) also seems like a hacky way to go.

Is there any way to set the page.tpl.php variable directly with hook_menu()? That would be ideal.

EDIT for clarification:

This is what I want to achieve:

function mymodule_menu() {

  $items['my-page'] = array(
    'title' =&gt; t('My Page'),
    'page callback' =&gt; 'mymodule_callback',
    'access callback' =&gt; TRUE,
    'page arguments' =&gt; array(),
    'page vars' =&gt; array('myvariable' =&gt; 'hello') // Obviously this doesn't work, but would be great
  );

}

function mymodule_preprocess_page(&amp;$vars) {

  if($something === 'my-page'){ // What to do here???
     $vars['myvariable'] = 'hello';
  }

}


Basically I want something within hook_preprocess_page &amp;$vars array to identify the route I have created with hook_menu. If I can define this somehow in hook_menu itself (or the callback) it would be even better.

I can use arg(0) but that doesn't account for any subpages, and I might want to change the route which means I need to change preprocess function too. Is there a better way?
Just as an option, you could use a specific page template for your path, and sub-paths.

/**
 * Implements hook_preprocess_page
**/
function HOOK_preprocess_page(&amp;$variables) {
  // Optional logic to check path condition
  // e.g arg(), request_uri(), current_path() etc..
  $some_condition = FALSE;
  if(arg(0) == 'base' || $some_condition) {
    // Set single page--base.tpl.php template, for /base and /base/subpath
    // Note: this overrides theme_hook_suggestions[]
    $variables['theme_hook_suggestion'] = 'page__base';
    // Sample template variable
    $variables['foo'] = 'bar';
  }

}


Then, in your theme, you can copy page.tpl.php to page--base.tpl.php and add whatever page specific markup you need in the template.

You could also add logic and template variables to hook_preprocess_page.  They would be available in your custom template. They can also be added there for the default page.tpl.php template. In any case, you will need some condition check for the specific target path match there.

Some relevant API functions to check the URL path include:


arg
current_path
request_uri


Note: arg() is also used by core template_preprocess_page to set the theme suggestions.


  Uses the arg() function to generate a series of page template suggestions based on the current path.