Drupal Sub-themes

Posted on 19 September 2009 by jose

Wow, time flies when you're having fun. I hadn't intended to spend the day playing with Drupal, but the incontrovertible fact is that it's almost ten already, so I have. The idea was to enable the Pirate module (Arrrr!!!) and then take care of a couple of security advisories that affected my installation, requiring that I update Drupal core and the Date module. This ultimately ended up leading to my creating a sub-theme for the Marinelli theme.

What I'd forgotten was that the last time I'd worked on my site, the Admin Menu module encountered a bug in its interaction with the Devel module, which was giving me fatal PHP errors when I authenticated. The anonymous view of the site was not affected, and at that moment, I didn't have time to go digging around to discover the cause, so I left my site up, but broken. It was long enough ago that I was surprised when I logged in and got the WSOD.

I renamed the Admin Menu module to something other than what Drupal was expecting just so I could access the admin pages for my site, and then I checked my modules for updates. Sure enough, there was a Devel update, and a little quick research determined that I could probably resolve my issue by updating Devel. A few Subversion checkins and checkouts later, and I had a mostly up-to-date system with a working Admin Menu. The only thing left to update was the Marinelli theme, which had added a few things for better OG support, something that didn't affect me at all.

I nevertheless realized that the easiest way to keep up with updates was to break out my Marinelli overrides into a sub-theme. With the help of KDiff3, I compared my version of Marinelli to the stock Marinelli 2.92 to the latest version, 2.96 (that's right, a three-way diff). The bottom line is that I was able to replace Marinelli with my own sub-theme, containing 5 modified templates (because I use the Block Class module and because I can't stand how inconsistent the page and node templates are when it comes to the code) and 3 CSS files (my resume styles, which override nothing, my print styles, which don't exist in stock Marinelli, and my actual Marinelli overrides, consisting of 75 lines of commented, well-spaced CSS). Not a whole lot to my modifications, but they're enough to make it a pain in the ass to upgrade; moving to a sub-theme makes this much easier. I just have to look at Marinelli's CVS diffs and, because my overrides are commented, I can see if I need to make any adjustments (highly doubtful, but I'm paranoid).

The one gotcha that's important: your sub-theme's template.php file (if it has one) has to avoid re-declaring functions already declared in the parent theme. If you want to override template.php functions, use your theme name as part of the function name, or you'll get fun PHP fatal errors and the WSOD. It's not much of a gotcha; you just have to make sure you know which template functions are necessary for your theme.

Latest poll

Which do you favor?