Check your version

This video covers a topic in Drupal 7 which may or may not be the version you're using. We're keeping this tutorial online as a courtesy to users of Drupal 7, but we consider it archived.

Creating dynamic templates for specific node types

Video loading...

Join Drupalize.Me to watch this video

Join today and gain instant access to our entire video library.

Log in Sign up
  • 0:08
    In this chapter, I want to take a look
  • 0:10
    at using Drupal's dynamic template system in order to create templates
  • 0:14
    that allow us to target specific node types.
  • 0:18
    If you remember, early on in the presentation, we talked about dynamic templates a little bit.
  • 0:23
    What this is going to do is allow us to have 2 different node template files,
  • 0:26
    one that's used for article nodes and one that's used for our basic page nodes
  • 0:31
    so that we can have different HTML output, depending on the node type.
  • 0:36
    I'm going to switch over to Drupal's documentation for a second
  • 0:38
    and just take a look at this.
  • 0:40
    This handy page tells us a lot of information about these Template Suggestions

Creating Dynamic Templates for Specific Node Types


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 documentation page that we look at can be found at

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.