Base themes and writing your own themes

For small websites it is often enough to use a contributed theme, perhaps with a tweak here and there. In professional web development few clients would accept having a site that looks like hundreds or thousands of other Drupal sites.

The art of writing new themes will not be covered in this book, but there is room for two tips for anyone hungry to develop a theme of her own:

  • Instead of building a new theme from scratch, you should use a base theme. This a theme written to be extended and built upon. Using a base theme will save you a lot of work in resetting parts of Drupal's standard markup and you will also get good support for older versions of Internet Explorer (which has a tendency to make web sites look broken). With a good base theme, at least 80% of your theming work can be accomplished by just writing CSS.
  • Instead of hacking and changing your base theme, you should create a sub theme, including only the things separating your theme from the base theme. This allows you to update the base theme when necessary, without jeopardizing your own work.

Installing contributed themes

Developing themes for Drupal is an art in itself and will not be covered in this book. Luckily, you don't have to write your own theme to be able to vary the look and feel of your Drupal site. There are plenty of contributed themes to download and use. Six months after Drupal 7.0 was launched, 169 themes were available.

You will find contributed themes at the same place as contributed modules at under the tab download & extend. Themes are installed in one of two ways, like modules:

Changing the theme of your website

At the toolbar, Appearance, you will find a list of all themes available on your Drupal site. (See figure A1.9) In a standard Drupal installation you will find four themes:

  • Bartik: This is the standard theme, used for non-administration pages.
  • Seven: This is the theme by default used on administration pages.
  • Garland: This is the default theme used in Drupal 6, ported to Drupal 7 as an alternative to Bartik.
  • Stark: This is a stripped-down theme that could be used as a base theme (see separate section).

Each theme has a set default link, used to set which theme should be used on non-administration pages. Just below the themes list is an option to select which theme should be used on administration pages.

Figure A1.9: The themes overview page allows you to select which theme should be used on your site.

TIP: If more than one theme is enabled, site builders can install ThemeKey or Switchtheme so your users can choose which theme they would like to use. This may be useful to offer a high-contrast theme to users with visual impairments.


At a large scale, Drupal does three things when a page on your website is requested. The first is that Drupal checks which files and libraries are necessary to collect the information on the page – and how much of the information the requesting user is allowed to access. The second is to actually collect all the information, which usually involves quite a bit of querying and poking in the database. The third and final step is to take the big, naked array of collected data and dress it up with different templates and HTML tags to make it presentable in a web browser.

The last step is called Drupal's theme layer and is governed by your site's theme. The theme layer is separated from the rest of the data management. This means a website can have its look and feel completely changed without having to change the content a bit. For anyone skilled in HTML, CSS, JavaScript and other languages used to present digital content, it also means the possibility to do an extreme makeover of Drupal's presentation.

TIP: Most Drupal themes outputs (X)HTML, but nothing in Drupal forces the content to be presented as a web page. A theme could for example present content as spoken text, or as XML files processed by other applications.

Elaboration: Using Features efficiently

It takes time and training to use Features efficiently and you are encouraged to start using Features to export configuration early on to get this training. Here are a few tips.

  • The best way of assuring that Features has captured all the settings you want to export is to install your features (mini modules) on a clean Drupal site. On the site used to build the features, non-exported settings in your database may trick you into believing that everything is exported.
  • Divide your site configuration into several different features. This makes it easier for several developers to work in a single project.It also makes it possible to enable and disable each feature individually on the resulting site. You can also reuse selected features on other sites more easily.
  • When dividing site configuration into separate features, you want the lines between the features to be as clear as possible to avoid conflicts. Usually this means that different sections or functionality on the site is kept in separate features. For example building a blog feature and a news feature. But you could also break the configuration up further, such as blog creation/management and blog display. In general, many small features are better than a few large ones.

Strongarm and update hooks

Features has solved many of the problems that used to block version control of Drupal configuration. But some problems remain.

In order for Features to be able to export the configuration, the corresponding module must save its settings in a way that Features can recognize. Practically all larger modules support Features, but many smaller modules don't. If you want to version control all the configuration in a project, you will either spend a lot of time improving a number of modules or have to find other solutions.

In particular there are a number of settings in Drupal core that are not natively recognized by Features. To solve this, the Strongarm module was written, acting as a bridge between Features and the settings stored in the Drupal variable table. Since many small modules have so few settings that they chose to store them in the variable table, rather than creating their own tables. Strongarm is able to pick up these settings and tell Features about them.


Subscribe with RSS Subscribe to RSS - Drupal 7.x