Web Development Tips

How to call customized page template in drupal pages?

Posted by: slvramesh on: July 13, 2010

Drupal template system is very interesting because you can call any of page template as to your decided page. The following way you can call page template in drupal.
1) As per node or content type
2) As per menu
3) As per your argument in menu

The above three categories are covers your all drupal pages. So the following code will used to get template suggestion as per node or menu or argument.


/**
* Override or insert PHPTemplate variables into the templates.
*/
function phptemplate_preprocess_page(&$vars) {
// first, proceed with a modifed version of the standard
// Drupal template suggestion calls
$i = 0;
$suggestions = array();
$suggestion = 'page';
while ($arg = arg($i++)) {
$suggestions[] = $suggestion .'-'. $arg;
if (!is_numeric($arg)) {
$suggestion .= '-'. $arg;
}
}
if (drupal_is_front_page()) {
$suggestions[] = 'page-front';
}
// next, check for templates that use the path alias
if (module_exists('path')) {
$alias = drupal_get_path_alias(str_replace('/edit','',$_GET['q']));
if ($alias != $_GET['q']) {
$template_filename = 'page';
foreach (explode('/', $alias) as $path_part) {
$template_filename = $template_filename . '-' . $path_part;
$suggestions[] = $template_filename;
}
}
$vars['template_files'] = $suggestions;
} // end path alias template check
if ($suggestions) {
$vars['template_files'] = $suggestions;
}

if (isset($vars['node'])) {
// When viewing a node focused as a full "page", it will suggest the node type.
// For example, a node type of "some_foo" will search for "page-some-foo.tpl.php".
$vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
}
}

The phptemplate_page_preprocess used to override drupal variables. The template file have been override the above code.

The same way you can user node template also.

Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.