
We will be covering the following recipes in this chapter:
- Understanding the anatomy of a theme
- Creating a sub-theme based on a core theme
- Overriding base theme elements in a sub-theme
- Changing the screenshot image of a theme
- Including a CSS file in a theme
- Enabling CSS optimization
- Creating the mysite module to hold our tweaks
- Adding a CSS file from a module
- Displaying a different theme for each day of the week
- Creating a fresh look using the color module
One of the more prevalent adages with respect to Drupal development and theming is:
Do not hack core!
Modules, themes, and other files which come with a stock Drupal installation should never be edited directly. In other words, we really should not need to modify anything outside the sites
folder which is designed to contain all our changes and customizations. The reasoning behind this is that most, if not all, aspects of core are accessible and modifiable through a clean and non-invasive process using Drupal's APIs. Therefore, hacking core modules and themes to get things done is almost always unnecessary and ill-advised.
Another reason why directly editing core modules and themes, or for that matter, even contributed modules and themes, is that whenever an upgrade of Drupal or said modules and themes takes place, we will very likely be overwriting the changes we have made, or at the very least, make the upgrade a trying exercise.
With respect to themes, let us take the example of a core theme such as Garland. As previously mentioned, it is a poor practice to edit the theme directly. The Drupal way is to extend the existing core theme using a sub-theme which, by default, is more or less an identical copy. This sub-theme can then be extended further and customized by overriding elements of the base theme,such as its stylesheets, template files, template variables, and so on.
In this chapter, we will look at the building blocks of a basic theme and then familiarize ourselves with the concept of the sub-theme and the various techniques available to extend, override and modify it according to our requirements.