Q: How can you easily specify an alternative page template to be used when displaying a node of a particular content type in Drupal 6?
A: Use the Node Template module, supply an alternative page template file in your target theme folder and configure your content type to use this new template.
Sometimes your webdesign may call for a slightly different page template when displaying a node of a particular type. For example I have been working on an ubercart eCommerce site and when displaying a product I want the product title not to be displayed where it usually is near the top of the page, but instead I want to display it in the product template itself, alongside the product's image.
It is easy to include the product title in the product template (using the contemplate module) but do you switch off the title that's displayed at the top of the page?
The tiltle is output by page.tpl.php and I could just edit page.tpl.php and remove the code that prints the title but then it would disapear for all pages, and that's not what I want!!
Instead I installed the Node Template module, it allows you to choose an alternative page template file for use with a given content type. It looks in your theme directory for files named:
page-yourname.tpl.php
I called mine - page-product.tpl.php
So how here's how to get it up and running - first install the Node Template module. Then make a copy of your page.tpl.php and name it following the format above. Now, edit the template as required, in my case I just removed the code that prints the node's title. Next, go to your content type's settings page (admin/content/types) and you will see a new setting called 'Template' in the 'Template Settings' section.
In this dropdown you should see the new page template that you just made, choose it and save - now when you view nodes of this type the new page template should be used.
If you're interested you can se how to do the same through code here - http://drupal.org/node/249726, but I reckon the module is less hassle!
PS 3/8/2010, Just a quick update - if you want to override a node template for a particular Node Id (not just for a node type) then have a look at this post:
Just started using this module - makes it nice and easy to hook these up and for lesser able bodied people to administer the content -> template relationship.
Did you find this post helpful? If so, we'd love to hear from you in our comments! If you found it really useful we'd love a link from your Blog-Web Site, to us!
Just started using this module - makes it nice and easy to hook these up and for lesser able bodied people to administer the content -> template relationship.
Cheers
Allen