Overridding the node.tpl.php File

Published October 21, 2009

If you've done much Drupal theming, then you're probably aware that you can override the default node.tpl.php template file on a per-content type basis. For example, if you have a content type called "food", then you can create a node-food.tpl.php that will be used only when nodes of type "food" are displayed.

A full list of template suggestions can be found on drupal.org.

There's a couple of "gotchas" that you need to be careful of when overriding node templates - as well as any other template files as well. First - whenever you create a new template file, be sure to clear your cache. Second, be sure your node template uses the "machine name" for the content type in the file name. For example, if you have a content type named, "Imageboard" and the "Type" is "image_board", be sure your node template is named, "node-image_board.tpl.php" and not "node-imageboard.tpl.php.

One final gotcha is that if you're using a subtheme and you want to use a custom node template for a particular content type, you'll also need to include a default node.tpl.php in the subtheme or your custom node template will never be seen by the theming engine.


That was easy! I created the node, but refresh did not work. I need to clear cache.

Submitted by Guest (not verified) on Fri, 02/26/2010 - 00:58

Sign up to receive email notifications of whenever we publish a new blog post or quicktip!