Drupal provides a lot of default template files when it comes to page, node and block output.
There are, however, a few instances when you may want to theme a page based on the content type - such as having a dedicated page for when videos are viewed (I’m doing just such a thing on this site).
What you need to do then is tell Drupal about the dedicated and specific template file you wish to use for that content type. The way to do this is with preprocess functions.
This video shows you the few lines of code you need. Of course, if you don’t want to watch the video then all you need is this.
<?php
/**
* Adding or modifying variables before page render.
*/
function phptemplate_preprocess_page(&$vars) {
// Page change based on node->type
// Add a new page-TYPE template to the list of templates used
if (isset($vars['node'])) {
// Add template naming suggestion. It should alway use hyphens.
$vars['template_files'][] = 'page-'. str_replace('_', '-', $vars['node']->type);
}
}
?>
Very useful, but 2 things you didn’t mention in text (I didn’t have time to watch video)
Are the answers to the above questions.
But it doesn’t seem to be working for me (I’m making a Zen sub-theme). I’ve cleared the caches and tried multiple content types / tpl files with no luck.
Also, what does this snippet do to page.front.tpl.php? Does it break it? Do you have to use the node id for your tpl file instead?
Any feedback you might have would be awesome.