Skip to Content

node.tpl.php Overview

| | |

Here's the official word from Drupal.org on node.tpl.php:

This template controls the display of a node, and a node summary.

View the Overview of node.tpl.php at Drupal.org

Node?

No really, what is a node? A node is an individual piece of content, so a blog post, a book page, a forum entry and an original CCK type entry are all nodes. So node.tpl.php is the template file that controls the display of nodes*.

node.tpl.php Basics

node.tpl.php looks very similar to page.tpl.php. That is no coincidence - node.tpl.php and page.tpl.php are meant to be used together.

node.tpl.php is the template for displaying generic nodes or individual pieces of content. For instance, when you're looking at the perma-link for a blog post you're seeing a single node displaying within the page template. You'll note that the URL for that perma-link will be something like "node/114." So a node is the unique piece of content on any page. Sometime multiple nodes are displayed on a page.

Where page.tpl.php is the template that displays the entire Drupal system, node.tpl.php is the individual piece of content that is outputted within page.tpl.php.

Like all *.tpl.php files this document contains XHTML and some embedded PHP. This particular file becomes the structure for your individual piece of content.

The theme_node Function

Like page.tpl.php, node.tpl.php is a template file used to override the default output of the theme function theme_node.

The theme_node function looks very similar to theme_page. It's purpose is to return a themed node. The default mark-up that is outputted isn't perfect. Here is an issue with the default output:

  • The <small> tag is used to contain the $links and the $terms - deprecated tags that only have a presentational purpose should not be used. CSS is preferred.

node-$type.tpl.php

*If you have a node.tpl.php file in your theme, this file becomes the default template that is used to display all node types (book, blog, page, forum, etc.).

You can also make *.tpl.php files for each node-type. An easy way to do this is to duplicate the node.tpl.php file and simply rename the filename to node-$type.tpl.php

drupal/themes/my_theme/node.tpl.php
drupal/themes/my_theme/node-book.tpl.php
drupal/themes/my_theme/node-blog.tpl.php
drupal/themes/my_theme/node-page.tpl.php
drupal/themes/my_theme/node-forum.tpl.php

The *.tpl.php file that has a name that corresponds with a recognized node-type (using the syntax above) will take precedence over node.tpl.php.

node-book.tpl.php for instance corresponds to the node type of "book".

Reply

The content of this field is kept private and will not be shown publicly.