Drupal - How to override default page.tpl from a module, for a specific page?

As per Stuart Clark's advice

All you have to do is to create a template, for example : mymodule/theme/special-page.tpl.php

and add this to your module

function mymodule_theme(){
  return array(
    'special_page' =>  array(
      'template' => 'theme/special-page',
      'render element' => 'page'
    ),
  );
}

function mymodule_preprocess_page(&$variables, $hook) {
  if ( my_condition() ) {
    $variables['theme_hook_suggestions'][] = 'special_page';
  }
}

You see, almost every page callback declared in hook_menu is wrapped in both html.tlp.php and page.tpl.php. That's because most modules will not declare the menu item's delivery callback, and it defaults to drupal_deliver_html_page. You can declare your own delivery callback and use a custom theme function (see hook_theme) to render your page. It will also make overrides easier for themers.

Tags:

Theming

7