Learning the Many Ways to Theme With Drupal 6
Packt’s new book, Drupal 6 Themes, takes the reader through the process of creating themes for Drupal 6. It does this by first giving an overview of how themes work in Drupal, then what exactly can be themed and finally takes the reader through several examples.
What is Drupal?
Essentially Drupal is a very flexible content management system that has been in development since 2001. One of its strengths is allowing users to modify much of its look and behaviour by over-riding default actions. This will enable developers to concentrate on what they want to change and leaving the rest as is– a method that will be familiar to users of some frameworks. Themes in Drupal are a collection of files organized in their directory controlled by a template engine that processes the files. While the book does touch a fair bit of Drupal’s structure, themes only really control the presentation layer, so this is not the book if you want to write your extensions modules.
How themes work in Drupal
The first two chapters cover what Drupal themes are and how the reader is going to work with them. With any content management system (CMS), there are limits to what can be altered without diving into the core of the application. Having once contracted for a company who had done just this and is now probably stuck with their custom version of Drupal 5, this is something you want to avoid. At the same time, you don’t want a web developer able to pick out your CMS from 20 paces– not to mention your graphic designer isn’t going to be too happy to be told every layout they do will have three columns and a blue gradient.
The good news is Drupal has a theming system that lets you put not only layout changes, but functionality changes together into a theme in its directory. This keeps your modifications together in one place and making it easy to distribute it. A bit like some other frameworks, it has a well-thought-out system where your theme can override certain Drupal defaults, be they style-sheets or functionality while keeping Drupal’s defaults intact for the parts you don’t want to modify. By the end of chapter two, users are already going to be able to install new themes and made minor changes to them.
What exactly can be themed?
The next part starts with an overview of template engines, concentrating on PHPTemplate and pure PHP templates. Drupal supports several template engines, though only PHPTemplate and pure PHP templates have examples given. At first, I found PHPTemplates confusing; after all, the code looks exactly like regular PHP. Still, the confusion comes from the name: PHPTemplates is not a new language, but more of a way of organizing files so that installing and uninstalling can be done from Drupal’s administration interface. These template engines are covered in chapter three, and they give a bit of an overview of PHPTemplates and plain PHP templates for examples.
This is followed by a guide to what files control what aspects of the standard modules (polls, forums, blog, etc.). Drupal has a large number of files — about 40 CSS files alone — so a fair bit of time can be saved by knowing where to look. Finally, Drupal’s overrides and intercepts are covered in chapter five. Intercepts are how to modify things people see on the screen, while Overrides are for making changes to default Drupal functions. Overrides and intercepts are the proper way to alter the look and functionality of Drupal, so it’s an important chapter to understand. By the end of these chapters, readers are going to know where to start modifying themes and what the process is.
The chapters that follow are practical examples of theming. Using the Zen template, the reader is guided through modifying an existing template and creating a new template using both PHPTemplates and regular PHP. Along the way, Shreves does mention a couple of tools useful for designing themes and appendix B also lists some Drupal modules which are helpful. Later chapters cover theming forms and dynamic templates (those that change according to the user or programmatic settings), so the reader should emerge with a pretty good idea how to proceed on to their templates.
The book gives a reader an overview of how themes work in Drupal, what can the themed and provides examples of theming the standard Drupal modules. By the end of the book, readers should be familiar enough to create themes in Drupal. The book then ends a bit abruptly with two appendix on the contents of the various Drupal style-sheets and some tips on tools to use for theming. Drupal has a large number of files, so a few of the chapters and the first appendix serve as a reference as well, making it an excellent book to keep around after you’ve finished the examples and are working on your themes.