How to customize page templates
Different 5.x page templates depending on node type
The list of "template suggestions" for a template can be modified in your template.php file. The following snippet will add page template suggestions for node type for the current page. That allows you to, for example, define a page-nodetype-news.tpl.php template which would apply to every page that displays a "news" node type.
<?php
// Add additional template suggestions
function _phptemplate_variables($hook, $vars) {
switch ($hook) {
case 'page':
// Add page template suggestions based on node type, if we aren't editing the node.
if ($vars['node'] && arg(2) != 'edit') {
$vars['template_files'][] = 'page-nodetype-'. $vars['node']->type;
}
break;
}
return $vars;
}
?>If you are using the Zen 5.x theme, look in your sub-theme’s template.php file and uncomment the SUBTHEME_preprocess_page() function and add the following code (without the <?php and ?> tags):
<?php
// Add page template suggestions based on node type, if we aren't editing the node.
if ($vars['node'] && arg(2) != 'edit') {
$vars['template_files'][] = 'page-nodetype-'. $vars['node']->type;
}
?>Note that template files cannot be located in the Zen subtheme's templates directory until these issues are resolved: #279573: Themes can't use node-story.tpl.php without node.tpl.php and #311201: template suggestions (like node-[type].tpl.php) do not work in subtheme folder.
Additions
For a drupal 6 equivalent, see:
Different page templates depending on URL aliases
The list of "template suggestions" for a template can be modified in your template.php file. The following snippet will add page template suggestions for each level of URL alias for the current page. That allows you to, for example, define page-music.tpl.php template which would apply to every page under 'music' path / logical directory. (This information is of particular importance to users of pathauto module who want to create, say, a landing page using a different tpl.php file.)
