Avoiding the Template.php of Doom (or, Overriding Theme Functions in Modules)

Avoiding the Template.php of Doom (or, Overriding Theme Functions in Modules)


Add Comment
Share
Source Articles
16
Monday, June 16, 2008
By admin
Drupal’s theming system offers developers and designers a flexible way to override default HTML output when specific portions of the page are rendered. Everything from the name of the currently logged in user to the HTML markup of the entire page can be customized by a plugin “theme”.

Unfortunately, this system can be its own worst enemy. Themes are very powerful, but in many cases they’re the only place where specific output can be changed without hacking core. Because of this, themes on highly customized production sites can easily turn into code-monsters, carrying the weight of making ‘Drupal’ look like ‘My Awesome Site.’

This can make maintenance difficult, and it also makes sharing these tweaks with other Drupal developers tricky. In fact, some downloadable modules also come with instructions on how to modify a theme to ‘complete’ the module’s work. Wouldn’t it be great if certain re-usable theme overrides could be packaged up and distributed as part of any Drupal? As it turns out, that is possible. In this article, we’ll be exploring two ways to do it: a tweaky, hacky approach for Drupal 5, and a clean and elegant approach that’s only possible in Drupal 6.

Leave a Reply

Your email address will not be published. Required fields are marked *