Community Documentation

Theming nodes by content type

Last updated November 18, 2011. Created by karschsp on February 19, 2005.
Edited by goron, h_dries, SLIU, bekasu. Log in to edit this page.

Note: To do this in Drupal 7 please see Drupal 7 Template Suggestions.

The file node.tpl.php is used to theme certain types of nodes. This single file generically covers all Content Types and you can edit it to make changes across the board as detailed on the node.tpl.php handbook page. To theme individual content types in different ways, you need to create a file node-[type].tpl.php in your theme's folder, where [type] is the machine readable name of the content type, for each type you wish to theme. Some examples:

node-story.tpl.php
Themes only Story type nodes.
node-page.tpl.php
Themes only Page type nodes. Note that this is different from page.tpl.php which controls the layout of the entire page including header, sidebars and so on.
node-forum.tpl.php
Themes only Forum type nodes.
node-book.tpl.php
Themes only Book type nodes.

In general, you can replace [type] with any content type name. One exception is the Flexinode module, which uses numbers to name the types. See Node Templates for Flexinode Content Types. Note that you cannot use node-admin.tpl.php to theme just the admin pages—but you can use page-admin.tpl.php to theme the admin "pages".

Once you have this new file, copy in the contents of node.tpl.php and modify it however you wish. All the variables listed on node.tpl.php can be used.

NOTE: When using phptemplate node-[type].tpl.php suggestions, there must also be an original node.tpl.php template present in your theme directory or the template suggestion is ignored.

This is also the case for subthemes. Just copy the parent themes node.tpl.php into your subtheme folder and refresh the theme cache.

More details can be found at the Core templates and suggestions handbook page.

Drupal 6

For more information on theming nodes by content type in Drupal 6, please refer to the following handbook pages:

Comments

Works with D6

This technique seems to work for D6 despite only listing "Drupal version: Drupal 4.6.x, Drupal 4.7.x, Drupal 5.x".

Different convention for D7 (Drupal 7)

In Drupal 7 use two hyphens.

node--article.tpl.php
Themes only Article type nodes.

node--page.tpl.php
Themes only Page type nodes. Note that this is different from page.tpl.php which controls the layout of the entire page including header, sidebars and so on.

node--forum.tpl.php
Themes only Forum type nodes.

Yep. this works

Wish I had scrolled down and read this earlier. Two hyphens! Is this a bug that's going to get fixed and then break my template?

Here's the page with full

Here's the page with full details on D7 tpl files: http://drupal.org/node/1089656

Dear, please give a template

Dear, please give a template full demo for custom content type.

Bto

Default implementation

See http://api.drupal.org/api/drupal/modules--node--node.tpl.php/6/source for the Drupal 6 version of node.tpl.php

Let's say I've created a content type called "my_content_type". I understand that you could template/theme that entire content-type by creating "page-node-my_content_type.tpl.php". But, what would be the best way to then further customize a single node of that content type (e.g., node 5555)?

I tried the following, but none worked:

page-node-5555.tpl.php
page-node-my_content_theme-5555.tpl.php
node-5555.tpl.php

None of these work. They all continue to use my original content-type template.

You could use
node--5555.tpl.php (two hyphens for Drupal 7)