Theming

Creating Dynamic Templates for Specific Node Types for Drupal 7

Last updated
Categories

This page is archived

We're keeping this page up as a courtesy to folks who may need to refer to old instructions. We don't plan to update this page.

Sprout Video

Shows how to create a theme template suggestion for a specific node type. In this chapter, we create a dynamic template for the article node type by copying the node.tpl.php into a node--article.tpl.php where the 'article' is the machine-readable name for the article content type. We add some specific styling to the node author submission information as well as the date. We also discuss how Drupal looks for the most specific template suggestion (i.e. the node id), then moves to more and more generalized template files like the content type, and then the node.tpl.php as the most general. The Drupal.org documentation page that we look at can be found at http://drupal.org/node/1089656.

Additional notes:
The field_tags variable relates to the corresponding tags field on the article content type. For every field you have on your node the $content variable will contain the rendered content of that node in a key that is the name of the field. So in this case $content['field_tags'] contains all of the tags applied to the node.

Additional resources

Drupal 7 Template (Theme Hook) Suggestions