I have a hook_menu like that:
function mymodule_menu() {
$items['mymodule-test'] = array(
'page callback' => '_mymodule_test_callback',
'access callback' => TRUE
);
return $items;
}
and the callback function:
function _mymodule_test_callback()
{
// processing
return $html;
}
I googled around but i cant find how to force the page template inside my _mymodule_test_callback function.
Edit: why i cant (or dont feel comfortable with) url-based suggestion
Url-based suggestion are easy to implement, however they can not completely fit my needs.
The template I have to use is determined in the _mymodule_test_callback function, according to very various aspects, for example:
- Does exists a node of type 'foo', and does the field 'abc' value's be 'xyx'? => choose template 'page-mymodule-foo.tpl.php'
- The node does exists, but the field 'abc' value is empty? => Choose temlate 'page-mymodule-bar.tpl.php'
- The node does not exist at all, but the user has the 'bimbumbam' role? => Choose template 'page-mymodule-foobarz.tpl.php'
...and so on.
I know this is a rare behavior, and that i could redirect instead of switching template, but actually the function body is not big and i prefer to do this way.
Is not possible?
page-mymodule-test.tpl.php
based on my understanding of Drupal 6 template suggestions, please let me know if i've misinterpreted the question.module_preprocess_page()
with&$variables
like mentioned in below answer? In similar situations I've done such stuff in mytheme_preprocess_page()
with function calls to modules to determine decision making conditions, one bad experience with White screen of death when calling function of module which is disabled made me usefunction_exists
andmodule_exists
before calling a function to be on safer side, but it goes without saying that though my approach worked for me its muddy and not recommended.