Theming Specific Content Types Within Drupal


Sometimes it is easy to overlook the obvious and search for a far more complex answer than is necessary. Different types of content(nodes) within your Drupal design may call for a different layout. With Drupal 5 it is extremely easy to create new content types and apply a new template for each content type.

The creation of new content types is now a core function within Drupal from Administer > Content Types > Add Content type - the "Type" field is the machine readable name for your new content type. Additional field types including image, text, email and URL can be easily added by installing and activating the Content CCK module.

Now, back to what we were talking about. Lets say that we created a new node type called "mystuff". To create a new layout for mystuff, create a new template file called node-mystuff.tpl.php, copy the contents from node.tpl.php and modify as appropriate. To differetiate between the different content types I find it handy to wrap each content type in a specific CSS class.

You can also use this method to theme other existing node types like:

  • node-forum.tpl.php for forum nodes
  • node-book.tpl.php for book nodes
  • Etc....

You can't theme flexinode or admin pages using the above method.

For a comprehensive list of variables available take a look at