Creating dynamic templates for specific node types

Drupal: 8m
Video Series
Information

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.

Discussion

Comments on this video

You need to be an active subscriber to comment. or .

Another dense but very thorough and practical walk-thru. What I particularly like about Joe's presentations is that he takes the time to explain new code and variables. Small exception with the 'field_tags' element here-- it's origins are not explained.

@stevieb. 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. Hope that helps clarify where it came from if not let me know and I can try and explain further.

Lullabot logo

Lullabot has trained thousands of Drupal developers & guided the development of some of the largest Drupal websites.