Often we are in a situation where we need one, or several pages of a website to have a completely different structure. When this happens you will most likely have to use a different page.tpl .
The simplest way to change your page.tpl is to use the website's URL to explain to Drupal what page.tpl it should be using. For example, to assign a different page.tpl to a page that is under “yourbasepath.com/splashpage” all you have to do is follow this one step process. Go into your theme folder, and create “page-splashpage.tpl.php”. Once Drupal recognizes the link (/splashpage), it will then know to use this specific .tpl file.
But what happens when you need to use the same template more then once? This is when a page preprocess will come in hand! Here is what we’re going to do:
On your template.php we’re going to preprocess the page. It looks something like this:
/**
* Override or insert PHPTemplate variables into the templates.
*/
function phptemplate_preprocess_page(&$vars) {
//variables to be preprocessed
}
Now we’re going to use $vars['template_files'] to tell Drupal which file should be used on a specific page. In the following example we will be using “page-splashpage.tpl.php" for the user/register, and also for the user/password pages.
/**
* Override or insert PHPTemplate variables into the templates.
*/
function phptemplate_preprocess_page(&$vars) {
if (arg(0) == 'user' && (arg(1) == 'register' || arg(1) == 'password')) {
$vars['template_files'][] = 'page-splashpage';
}
}
Now you can change the "if statement" to satisfy whatever condition you need, node types, paths, etc...
Have a happy theming!

Comments
Interesting technique, but couldn't we just use use symbolic link here ?
@sushilhanwate you could try this:
/**
* Override or insert PHPTemplate variables into the templates.
*/
function phptemplate_preprocess_page(&$vars) {
if (arg(0) == 'user' && arg(2) == 'messages' ) {
$vars['template_files'][] = 'page-yourtemplatename';
}
}
not too sure about the arg(2) part, maybe you'll have to parse the URL write an if statement satisfy the condition of an url ending on /messages
You should look into Context3's Context Layout module.
For a maintenance page Drupal uses maintenance-page.tpl.php . Take a look on garland to see how it is done. It has some default behaviours ready for you.
Then you can theme it similar to your page.tpl
Regarding the symbolic link I've never used this technique.
Cheers!
for a maintenance page what is the best solution? using a .tpl file or template.php?
What is the solution for dynamic link like "mysite.com/user/1/messages"
Please Give solution if anyone has any idea.
I'm really just getting started with Drupal...
So if I set up 2 new page.tpl.php files: page-news.tpl.php & page-careers.tpl.php, is there a standard URL that I can access them at?
there is no function for maintanace.tpl.php in template.php
Hi, I,ve tested both of them, and Denis`s solution worked for me, I might say it is more logical, because it uses drupal_get_path_alias, in case if you are using Not default node/*, it is correct solution. (I gets path set by admin).
arg(0) says 'node' instead of 'user'
I used this variant :
function phptemplate_preprocess_page(&$vars) {
$path = $_GET['q'];
$path = drupal_get_path_alias($path, $path_language = '');
$patharray = explode("/", $path);
if ($patharray[0] == 'news') {
$vars['template_files'][] = 'page-node-news_page';
}
}
function phptemplate_preprocess_page(&$vars) {
$path = $_GET['q'];
$path = drupal_get_path_alias($path, $path_language = '');
$patharray = explode("/", $path);
if ($patharray[0] == 'news') {
$vars['template_files'][] = 'page-node-news_page';
}
}
Would using a variant like this be a problem for iPhone users and such? I've recently been looking into optimizing websites for phone browsers, but I still have no clue.
Post new comment