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

Very useful article, thanks.

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

Nemo's picture

Colourise Logo Issue

Hello Dude, nice blog, I just stumbled on it now, it has some good useful tips and informations one can find helpful but if you are not too busy can you give help me on something. I have the exact same theme installed on my drupal site and it seems really nice to use but I have two problems.
1. I have tried but failed in cahnging the default rainbow curtain with my own logo or pix just as you have done, but the page still re-loads the same image even though I have manually changed the bg.jpeg file, could you tell me how you did yours?
2. Following gibbozers instructions in the drupal support forum, I was able to add my custom logo by upload, but the logo still apperas on the left side of the page instead of the centre or over the rainbow curtain, I know that it is a css tweak issue but I dont know what to do, I know you aint the official support for this theme but I know you got the answers, please can you come to my assistance, you will be doing me a major favor. Thanks for a prompt response.

Olivier Biot's picture

Cache interfering?

Most likely you are being served a cached version of the page. Indeed, Drupal caches the theme files for efficiency reasons. This means that they’re not read from disk every time you do a page request.
First, visit Administration » Site configuration » Performance (admin/settings/performance). Scroll to the bottom of this page, and click the “Clear cached data” button. This effectively flushes the theme cache (as well as other Drupal caches).
Once you did this, reload your page. This should display the new artwork in your theme. If not, I strongly suspect your background image is cached by your browser. You probably replaced it while preserving its name to avoid editing the theme. (Actually, this is not needed, since the Colourise theme provide facilities for overriding the style sheets in a file named custom.css. This can be configured in the Colourise theme.)
In this case, you must flush the cache of your browser, or do a force reload of the page.
Hope this helps!

Nemo's picture

Just cant flush it out

Yeah, thanks for the prompt response ! Well could you believe that before I posted earlier, I had already cleared all data cache at least twice, I had also done the same for my browsers after your response, I went back and cleared it all over again at least four times over. I then went to the physical folder location and even deleted the file (i can easily re-upload it again) but the file its still showing, men! I am getting burnt out dealing with something so minute yet squandering my quality productive time, if I had another nicely dark theme I would have busted it all together, thats the problem with the free themes, no support, the dude that ported this theme into drupal don’t even give a flip in the drupal forum, if you have issues or not; you just have to figure stuff out for yourself, do you have any other suggestions why this file keep showing up yet, I can’t seem to loacte it anywhere, thanks again for a prompt response.

Olivier Biot's picture

Could you share a link?

If you post a link to your site I can have a look. Just tell me what I am supposed to see.

Nemo's picture

Yeah, I saw your response,

Yeah, I saw your response, but I had to quickly catch a world cup match but when I returned to drop the link, an idea hit that I should delete the theme from my website altogether, then re-download a fresh copy, open it up and change the bg.jpeg on my desktop, then re-upload the folder anew having altered the file on my localhost. This I did and that did it, so I have my logo nicely placed where I want it. Thanks ounce again but can I come in often to blog and ask a few questions from time to time cos, you are definately way out of my league technically speaking, if you don’t mind me turning you into answer man.

Olivier Biot's picture

That works as well

Uninstalling and deleting the theme, then re-uploading effectively clears the cache as well.
Feel free to fire your questions {#emotions_dlg.grin}

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.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Adds typographic refinements.

More information about formatting options

By submitting this form, you accept the Mollom privacy policy.