Skip to main content
Tweeted twitter.com/#!/StackDrupal/status/240464087715291136
added 850 characters in body
Source Link
Strae
  • 890
  • 2
  • 9
  • 25

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:

  1. Does exists a node of type 'foo', and does the field 'abc' value's be 'xyx'? => choose template 'page-mymodule-foo.tpl.php'
  2. The node does exists, but the field 'abc' value is empty? => Choose temlate 'page-mymodule-bar.tpl.php'
  3. 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?

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.

Is not possible?

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:

  1. Does exists a node of type 'foo', and does the field 'abc' value's be 'xyx'? => choose template 'page-mymodule-foo.tpl.php'
  2. The node does exists, but the field 'abc' value is empty? => Choose temlate 'page-mymodule-bar.tpl.php'
  3. 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?

Source Link
Strae
  • 890
  • 2
  • 9
  • 25

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' => '_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.

Is not possible?