Drupal Theme from Scratch Drupal Theme from Scratch icon
Theming a Drupal 7 Website



Your Drupal 7 Home Page Template

I said before that Drupal, by default, will use the page.tpl.php file to dictate how your home page is displayed. The page.tpl.php will control all your pages by default unless you have more templates.

The most common way to override the home page with a custom template is to take a copy of the page.tpl.php file and rename it as page--front.tpl.php. Drupal will automatically use that file instead of the page.tpl.php file for your home page.

However, to prevent having to use PHP includes for your header and footer sections and attach them to both the page.tpl.php and the page--front.tpl.php (or worse: adding the header and footer code to those files), I use a different strategy...

  1. Create a content type called 'home page'
  2. Make a copy of the node.tpl.php file and rename it as node--home-page.tpl.php
  3. Create a new 'home page' node by going to Content > Add Content > Home Page
  4. Assign this new node/page (confusing, I know) as the front page by going to Configuration > System > Site Information and put the title of your new page in the box under Default front page and then click 'Save configuration'

Now you can use page.tpl.php to hold the code of your header and footer across the site without the need for includes or needing to maintain the code in multiple files.

Usual Way

page.tpl.php

header.php
CONTENT
footer.php
page--front.tpl.php

header.php
CONTENT
footer.php
header.php

   CODE
footer.php

   CODE

Better Way

page.tpl.php

header code
CONTENT
footer code
node--home-page.tpl.php

NODE SPECIFIC CONTENT

The only way this strategy would not work is when you need multiple page-level templates. But that need won't present itself until you require the use of unique headers and footers on different pages. And when that day comes, it's easy enough to go back to using page--front.tpl.php.

In theory you might be able to hard code your header and footer into the html.tpl.php, but you can't load blocks the same way. I may be wrong about this.


*If you do not see the social network icons here, it is because you have an ad-blocker running. Deactivate it for this site if you want to share this link. It is safe. There are no ads on this site.

This documentation is a work-in-progress. As I continue to learn more about the software, I will try to keep this documentation updated. I'm no expert of anything, so if anyone feels they need to correct me about something I've written or wish to add some additional tips, feel free to mention it in the comments.

"Drupal 7 Theme from Scratch" was written by TenTen71 because no one else would.