Drupal’s Page Template System

Is it heresy to write about Drupal on a WordPress blog?  I don’t think it is…

Anyway, since Drupal is my favorite FrameWork/CMS, and most of my web development/design posts will relate to building Drupal sites, I figured I’d dive right into one of the parts of Drupal that I understand the least: the Template system.

I’m the first to admit that I am more comfortable writing php code or SQL queries than I am designing user interfaces, but they are a necessary evil I guess… (the users I mean).  Anyway, I have typically avoided mucking around with templates anymore than I had to.  I like to develop custom modules and upload them to the site.  It seems clean and easy, and I never really need to do much in the way of custom page layouts… until I did.

There is really no way to avoid it, at some point you are going to want to make a custom page.tpl.php file and I am at that point now.  I am trying to limit my use of panels as much as possible so for the site I’m working on now, I’ll be over-riding the page template file for my own custom types.

// Drupal Page Template

So the first question is: what is a template file?

Here is the official api doc: http://api.drupal.org/api/drupal/modules%21system%21page.tpl.php/7

A nice visual of how all the theme files work together: http://drupal.org/node/171194

This file gives you a good idea of what variables are available to you at the time the template file is used.  The page template is the one that I am interested in at the moment, but it is not the only template, rather one that controls a certain aspect of the layout.  There are many other aspects.

// Over-riding page.tpl.php

I thought this thread had some good info on how to override the page.tpl.php file, and for the home page: http://stackoverflow.com/questions/1869666/drupal-create-a-custom-page

Another answer thread about how to override page.tpl.php: http://drupal.stackexchange.com/questions/4810/how-do-i-override-the-default-page-tpl-php

Here is the definitive guide to overriding template files from Drupal.org: http://drupal.org/node/1089656

More info from Drupal.org on custom theme suggestions (aka theme hooks): http://drupal.org/node/223440#custom-suggestions

Page templates explained for a “noob” (like I feel now) on Drupal.org: http://drupal.org/node/1038210

More examples of how to (and how not to) write template suggestions for Drupal 7: http://drupal.org/node/1035656#comment-3996684

// Aftermath

So these are the resources I’m going to start with.  Please feel free to post any suggestions you may have.  I’ll edit this with new info to let you know how it went and if I ran into any snags…

comments powered by Disqus