Drupal theme hacking - creating a sub-theme

In a previous blog post I introduced the basics of how Drupal themes work. Let's dig a bit deeper and create our own sub-theme. What you need, is a working Drupal environment and at least one custom theme installed in sites/all/themes. During this tutorial I will create a sub-theme for the Colourise theme. If you want to use a different starting theme, the explanation below should still apply (apart from the name of the parent theme).

The sub-theme I want to design is based on the Colourise theme, and will be used for my ShutterFreak.net website, hence the very original theme name “ShutterFreak Colourise” {#emotions_dlg.grin}

The first step in creating a Drupal theme (or a Drupal sub-theme), is creating a theme directory in sites/all/themes. If you manage a theme and all of its subthemes, then it makes sense to create the sub-theme directory as a subdirectory of the parent theme. This is not at all a hard requirement. I decided to create the sub-theme directory on the same level as the parent theme's, hence the “ShutterFreak Colourise” theme resides in sites/all/themes/shutterfreak_colourise.

Next we have to create the ‘theme info file’ in the theme directory. I named this file shutterfreak_colourise.info. The format of this file is “KEY = VALUE”. Lines that start with a semicolon (‘;’) are comments. At the very minimum, this file should contain this:

; $Id: $
name = ShutterFreak Colourise
description = Dark tableless design with valid XHTML/CSS, based on the Colourise theme.
version = 0.1
core = 6.x
engine = phptemplate
base theme = colourise

What does this mean?

  1. $id: $ is a CVS or SVN placeholder. When this file gets checked in, this placeholder will automatically be replaced with basic versioning and tracking information from the source code control system. Since this line starts with a semicolon it is treated as a comment by the parser.
  2. name specifies the human readable name of the theme. This name appears in admin/build/theme.
  3. description gives basic information about the theme. If it depends on another theme, make sure to specify this here, preferably with a link to the parent theme.
  4. version is the version of your sub-theme.
  5. core represents the core Drupal version your theme works for. For Drupal 6, this value is 6.x.
  6. engine represents the theme engine that applies to this theme. The built-in Drupal theme engine is phptemplate.
  7. base theme is the most important statement here: it specifies the relationship between the “ShutterFreak Colourise” theme and the parent theme: Colourise.

The last finishing touch you may want to do, is adding a custom favicon. There are various on-line resources that accept an image and will transform it for you into a valid favicon.ico file. The favicon for your theme must reside in the theme directory. In my situation it resides at sites/all/themes/shutterfreak_colourise/favicon.ico.

Now it is time to try out your first sub-theme: navigate to admin/build/theme, enable your theme, and behold! Now you can start playing around with blocks and position them in your theme.

In a next post we'll dig still a bit deeper in how to develop a Drupal theme. Time to write some PHP code by then Wink

Nemo's picture

Great Article

Howdy,

I stumbled upon this article when looking up resources for an internal Drupal web page I'm working on for someone. I'm using the same Coulorise theme as you and I found the above sub-theme article very informative. Especially the part about favicons, which will be very helpful. Smile

I've been searching around your site and I had two more quick questions for you. First off I was wondering what wysiwyg editor you were using. I had tried a few but none of them quite did what I wanted them to do. I was also wondering what module you were using for your photo gallery. The one I am currently using isn't really working out all that well.

Thanks for the great article and if you could help with the other two questions it would be much appreciated. Cool

Olivier Biot's picture

Re: Great Article

Thank you for your reply. I am glad to see it is helpful for you Smile. I should resume writing the ‘Drupal Theme Hacking’ sequel but I've been busy with some semantic matters in the meantime…

To answer your questions:

  1. The WYSIWYG editor I am using is TinyMCE (version 3.2.7 at the moment), and it is made accessible to Drupal through the wysiwyg module. This module provides a generic framework to integrate your preferred WYSIWYG editor in Drupal. It is thr preferred way to integrate a WYSIWYG editor nowadays. In the past I have been using FCKEditor, but I decided to revert to TinyMCE due to a couple reasons. One of them being the availability of the TinyMCE Node Picker module which facilitates linking to existing content (nodes) on your Drupal site.
  2. The photo gallery is not Drupal based since it started before I ventured into Drupal. It is based on the free JAlbum tool which generated albums based on readily available skins and your photos (including tons of metadata included in the photos). I have been looking at ways to integrate photo albums in Drupal but so far I did not find yet any conclusive solution to fit my needs. Hence I stick to JAlbum for my photo galleries Smile.

Hope this helps!

Olivier

Nemo's picture

this is a very helpful

this is a very helpful article thank you i was looking to do something like this for long time

also i like the style of the site

greeting

Nemo's picture

Very useful article, thanks.

Very useful article, thanks. I thought that sub-themes could be created just from "base" themes. Thanks.

Post new comment

The content of this field is kept private and will not be shown publicly. If you have a Gravatar account, used to display your avatar.
By submitting this form, you accept the Mollom privacy policy.