Different 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 page-nodetype-news.tpl.php template which would apply to every page which node is news.
<?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 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;
}
?>
For a drupal 6 equivalent,
For a drupal 6 equivalent, see:
http://drupal.org/node/223440
http://drupal.org/node/223430