Change page.tpl template inside a hook_menu callback I have a hook_menu like that:

function mymodule_menu() {
    $items['mymodule-test'] = array(
        'page callback' =&gt; '_mymodule_test_callback',
        'access callback' =&gt; 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?
You cannot directly change the page template from a page callback. You can either bypass the full page rendering by printing your page content from your page callback. Or you can use a global variable to trigger addition of template suggestion in hook_preprocess_HOOK implementation.

function _no_template_page_callback() {
  // ... processing ...
  // Print the result, and bypass the page template (so no blocks, no CSS, no JavaScript, etc.). 
  print $html;
}

function _template_suggestions_callback() {
  global $MODULE_page_template_suggestions;  
  // ... processing ...
  // Set flag to trigger usage of our custom page template. 
  $MODULE_suggest_page_template = $suggestions;
  return $html;
}

function MODULE_preprocess_page(&amp;$variables) {
  global $MODULE_page_template_suggestions;
  if (!empty($MODULE_page_template_suggestions)) {
    // Use template suggestions set from _template_suggestions_callback the module.
    foreach ($MODULE_page_template_suggestions as $suggestion) {
      $variables['template_files'][] = $suggestion;
    }
  }
}