Theming and Subtheming

There are two ways you can custom theme your Drupal site. The first is to create an entirely new theme, either from scratch or by using another theme as template. The second is to create a subtheme—a theme that exists as a subdirectory of another theme, making use of much of the previous theme's settings, while still having a custom look and feel. I used both approaches for my sites. I created a custom theme for Just Shelley and Painting the Web, while this site is a subtheme I've named Flame, based on the default Drupal Garland theme.

All themes require an .info file, which identifies the theme and theme components. The following is the .info file for Painting the Web.

name = Painting the Web
description = Single column, fixed width
core = 6.x
engine = phptemplate

Included is the name, the description, the Drupal core, as well as template engine, in this case the default PHPTemplate engine.

The .info file and other theme components are installed in an appropriately named subdirectory under the main /themes subdirectory. Also included in my Painting the Web theme subdirectory is a style sheet, named the default, style.css, in addition to stylesheets specifically for Internet Explorer, a node.tpl.php file containing the design template used for displaying the site's posts (known as "nodes" in Drupal), and the page.tpl.php file providing the template design for the page. Rather than design from scratch, I adapted the Simplex2 theme to my own, since it's one of the cleaner designs.

The Flame design used in RealTech is different because I created it as a subtheme of the default Drupal theme, Garland. A Drupal subtheme doesn't require anything more than an .info file, such as mine for Flame, which is named flame.info.

name = Flame
description = Tableless, recolorable, multi-column, fixed width theme.
version = VERSION
core = 6.x
base theme = garland
stylesheets[all][] = flame.css

Included in the file is identification of the basic theme, Garland, as well as an identification of the subtheme stylesheet, flame.css. The subtheme CSS works with the Garland style.css, so all elements don't have to be styled: only the ones that differ from the parent theme.

The subtheme files for Flame are included in a subdirectory named "flame", located in the Garland theme subdirectory. No other files other than the .info file are necessary, though it wouldn't make sense not to have a subtheme style sheet. The only reason I provided a page.tpl.php file is because of processing I added for XHTML support, which I'll discuss in a later section. I copied the one from Garland and only added the additional XHTML processing. Anything that is not overridden in the subtheme is inherited from the base theme, and anything not provided in the base theme, is provided either by the template engine, or the Drupal core.

Of course, subthemes aren't completely without challenges. For instance, Garland is a fairly complex, multiple layered theme, so it can be difficult to figure out which element needs styling, and in what context. I found that the Web Developer Toolkit extension for Firefox, with the View Style Information option, to be absolutely essential in identifying elements and their current CSS settings.

I still use Garland for the Administrative theme because of my XHTML settings in my subtheme. Since I can't always control the page contents in the administration pages, I don't want these served up as XHTML. However, I did change the default blue color to the same color scheme I used for this site: Mediterrano. Drupal themes can be designed in such a way that the color schemes can be dynamically changed, without recourse to the style sheet, as well as being able to configure other things, such as location of favicon, logo, whether to include a search form and so on. The configure option is a link next to each theme in the Themes site configuration page, alongside a radio button selecting one theme as the default.

Themes | Burningbird's RealTech
Uploaded with plasq's Skitch!
Themes | Burningbird's RealTech
Uploaded with plasq's Skitch!

In addition to the stylesheets and page templates, I also provided a template.php file for all of my themes in order to override the default output for one PHP variable, $head.