Drupal 7 theme structure
I decided to create an explanatory graphic that ilustrate the different theming portions of Drupal 7 and how to access and modify them. This is not a theming tutorial but a quick guide to see the different parts of a Drupal theme.

Notes:
-
Page.tpl.php is basically where your main layout is. If you are starting from an HTML file, you can do the same as me and rename it to page.tpl.php and start populating the necessary elements. You can see which elements here.
This page needs to contain everything that goes inside the body (you shouldn't add the <body> tags here).
-
In Drupal 7 everything that holds content is a region, even the region that holds the "content" block.
-
Node.tpl.php is the themed representation of a content entry and when listing content this file will be called multiple times, one after another.
-
A block is just a piece of content that can be plain HTML or be generated from a module. (Like the Login block)
-
A region is what holds multiple blocks. These are the defined in the .info file and called in page.tpl.php
Worth mentioning:
-
When creating the theme.info file, starting from Drupal 7 you need a region called "content" or the theme will show up as incompatible in Appearance settings.
-
I'm not including all the TPL files but the ones I use the most.
Core TPL Files
Here's a list of the core TPL files source code. It's always good to go back to them to see what you have available on each template file.
- html.tpl.php
- page.tpl.php
- region.tpl.php
- block.tpl.php
- node.tpl.php
- comment-wrapper.tpl.php
- comment.tpl.php
- field.tpl.php
There are many more TPL files but these are the most used ones.
Creating a basic theme
First of all pick a name like "mytheme2011" and create a folder in:
/sites/all/themes/mytheme2011
Then inside, create the file mytheme2011.info and add the files you will be using. Here's an example for a simple site
name = "MyTheme 2011" description = " First version of it" version = "1.0" core = "7.x" engine = "phptemplate" stylesheets[all][] = "css/html5reset.css" stylesheets[all][] = "style.css" scripts[] = "scripts/main.js" regions[top] = Top regions[right] = Right regions[content] = Content regions[footer] = Footer
Now you should be good to go. Go ahead and create page.tpl.php and start populating the content. Pro Tip: Include important variables like $messages as it is your way of debuging.
Like a said, this is not intended as a theming tutorial but as a quick guide for starting a new theme. Leave a comment if you would like to see something added to it.
latest posts
About
Hi, I'm Ivan Soto Fernandez (yes, two last names). I'm a chilean web developer living in Edmonton, Canada. I'm also an anime fan, Gundams lover and gamer. Welcome to my blog.
You can read more about me or follow me on Twitter or any of the following social websites.