What are template files and suggestions?

Submitted by Marc on Wed, 09/22/2010 - 10:59pm

Template files are what Drupal uses to determine how to render the HTML for a page. When you wish to create a custom theme, there are several files you will likely include in your theme's directory:

  • page.tpl.php - this controls the overall look and feel of your site (slight change for Drupal 7). For those of you who have coded sites with HTML (and CSS), this is like the index.html page you created.
  • node.tpl.php - this controls how a node is built
  • block.tpl.php - this controls how a block is built

These files are only the tip of the iceberg, though. Core provides you with many more templates and suggestions. Here are a couple additional templates you may be likely to work with in a custom theme:

  • comment.tpl.php
  • box.tpl.php (deprecated in Drupal 7)

Suggestions are just a way for you to further customize the look of a page.

Template suggestions are alternate templates based on existing .tpl.php files. These suggestions are used when a specific condition is met and a matching file exists.

The easiest way for you to start to get a handle on these concepts is to start playing with them! Why don't you have a look at page.tpl.php inside of modules/system? Just don't hack core! You can easily create your own theme in which to experiment. Then you can copy page.tpl.php into your theme and modify it to your heart's content.