I am coding a module which contains a "please wait" page.

On this page I need to override the default page.tpl template so I can render the "please wait" message alone without all the other regions and "site chrome".

How do I tell drupal not to use the default page.tpl and use my page-special.tpl for the specific "please wait" page ?


Please note that I am coding a module, not a theme. So everything should be done from inside the module.

  • what is the path to this page? – Jimajamma Jun 27 '12 at 16:06
  • the path is, say, /mymodule/my/path – redben Jun 27 '12 at 16:17

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.

  • interesting though it looks like "rooting" the problem :) – redben Jun 28 '12 at 9:17
  • 1
    How is this like "rooting"? It is exactly the intended use of these functions and an ideal way to achieve what you are looking for from an implementation and maintenance perspective. – sheena_d Jun 30 '12 at 4:40

You should make a copy of page.tpl.php and rename it page--node--1.tpl.php Then you can style the new page. When you create the new file, remember to clear the cache. You can find more info here http://drupal.org/node/1089656 and here

  • page--node--1.tpl.php will theme the output of node/1 which I doubt is the output of his custom module... – Jimajamma Jun 27 '12 at 16:11
  • I am coding a module. Your suggestion works when your coding a theme. How do I tell Drupal to look for the page-my-path.tpl inside my module directory? – redben Jun 27 '12 at 16:16
  • So, basically it's a transition page. In this case, you need to create a node with Please Wait. You need to rename the page.tpl.php in page--node--NID.tpl.php, clear the cache and modify the the page with you custom code. Tell us more specs. – Tyler Durden Jun 27 '12 at 16:23
  • this page has a begining of an answer : "...Note for module-provided templates: A module can provide its own page template files. It is done in hook_theme()..." but I am still not getting the whole picture – redben Jun 27 '12 at 16:29

You can use this hook

function theme_preprocess_page(&$variables, $hook) {
$variables['theme_hook_suggestions'][] = 'page__special';

but you should have a tpl called page--special.tpl.php

  • I have implemented the hook_preprocess_page in my module and added suggestion page_wait. I have a template called page-wait.tpl.php in my module directory, (the path to my page is /wait ) it is still not working :/ I also added this to mymodule_theme() : ` 'page' => array( 'template' => 'theme/page-wait',` 'arguments' => array( 'content' => NULL, 'show_blocks' => FALSE, 'show_messages' => TRUE, ), ), ` – redben Jun 27 '12 at 16:41
  • I am sorry I forget that its a theme_preprocess_page you have to write it on template.php in your theme if your theme called redben so it will be redben_preprocess_page also try to make it page--wait not only page-wait and put it in template folder in your theme – Ahmed Jun 27 '12 at 16:49
  • Thanks I corrected the new double dash for d7. On the other hand I am not working on a theme. In fact I am working on a module... so everything should be done from inside the module – redben Jun 27 '12 at 16:51
  • about hook_theme you can add you template beside yourmodule.info and in your code use this $items = array('data' => array('#theme' => 'page_special','#node' => $node,), 'class' => array('page_special'), ); $output = $items;return $output; – Ahmed Jun 27 '12 at 16:51
  • I did this and i am getting a page inside a page :D – redben Jun 27 '12 at 16:58

try using this

function mymodule_menu()
 $items['test'] = array(
        'title' => t('Testing'),
        'page callback' => 'test',
        'access arguments' => array('access content'),
        'type' => MENU_CALLBACK,
return $items;

function test()
    return theme('test');
function mymodule_theme(){
    return array(
        'test' => array(
            'template' => 'test'//name of template file, place test.tpl.php in your module
  • I am not looking for this... with your suggestion, header and footer and other regions are displayed in the output. I'd like to override page.tpl.php from withing my module – redben Jun 27 '12 at 17:37
  • it seems what you want to do, can be achieved by "echo theme('test');" instead of "return theme('test');" but don't know if its good practice or not... – Ashu Jun 27 '12 at 18:04

I cannot find a way to override the html.tpl.php in my module. My use case was to create an "interstitial" page to display pre-roll video or an ad, similar to how forbes.com does it. Here is the user story:

"As a user, my first visit to the site will present me with an interstitial page before viewing content. WHen the page is displayed, a cookie is set in the user's browser preventing the interstitial from displaying on subsequent visits for the next 24 hours."

I created a hook_menu creating a page with a path called "welcome"

 * Implements hook_menu().
function liveinterstitual_menu() {
  $items = array();

  $items['welcome'] = array(
    'title' => 'Welcome to San Angelo LIVE!',
    'page callback' => 'liveinterstitual_welcome_page',
    'page arguments' => array(),
    'access arguments' => array('access content'),
  return $items;

The page callback is liveinterstitual_welcome_page(), and it looks like this:

function liveinterstitual_welcome_page() {
  // If you want the sidebars and everything in the theme layer, uncomment the next line
  //return theme('liveinterstitual', array('content' => $content));
  //else, to spit out a static html page, save the page to this module's dir and do this:
  echo file_get_contents( drupal_get_path('module','liveinterstitual') . '/liveinterstitiual.html');
  //Shut down Drupal cleanly

In short, I byassed the entire theme payer by piping the contents of a flat html file. Drupal has similar functions in core that do this by delivering a JSON array for ahah callbacks, for example.

I am open to other ideas, but this one appears to work for now.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.