Drupal - Page Template for Node Type

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:

http://www.pridedesign.ie/content/drupal-nodetplphp-node-id

glove
Stranger
Stranger's picture
Thanks!

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

Joined: 10/10/2008
User offline. Last seen 1 week 3 days ago.
You're welcome Allen, glad

You're welcome Allen, glad you found it useful!

-----------------------------------------------

Award Winning Web Design Cork : Pride Web Design Cork

-----------------------------------------------

Joined: 08/01/2009
User offline. Last seen 3 weeks 4 days ago.
Just a quick update - if you

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:

http://www.pridedesign.ie/content/drupal-nodetplphp-node-id

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You can use BBCode tags in the text.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Image CAPTCHA
Copy the characters (respecting upper/lower case) from the image.

Pride on FacebookPride on TwitterPride on TwitterPride on Twitter

Join Our Newsletter

* indicates required

Irish Internet Association

finalist.png
phone-number.png