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' => t('My Page'),
'page callback' => 'mymodule_callback',
'access callback' => TRUE,
'page arguments' => array(),
'page vars' => array('myvariable' => 'hello') // Obviously this doesn't work, but would be great
);
}
function mymodule_preprocess_page(&$vars) {
if($something === 'my-page'){ // What to do here???
$vars['myvariable'] = 'hello';
}
}
Basically I want something within hook_preprocess_page &$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?