Drupal 6 Theming Cookbook
上QQ阅读APP看书,第一时间看更新

Creating myzen, a Zen-based theme

While building a custom theme from scratch is great, most themers prefer to use starter themes as the base for their designs. Starter themes save time and effort as we do not have to perform tedious repetitive tasks and can rely on a tried and tested structure to use as a foundation for our theme.

In this recipe, we will be looking at creating a theme based on the most popular of all starter themes available on drupal.org, Zen.

Getting ready

Download the theme from http://drupal.org/project/zen and install it following the instructions in the first recipe from Chapter 1, Drupal Theme Basics.

How to do it...

The Zen theme provides a starter kit which can be used to kick-start our theme.

  1. Navigate to the newly installed Zen theme's folder at sites/all/themes/zen. Copy the STARTERKIT folder inside it.
  2. Paste this folder into sites/all/themes. Rename the folder to the name of our new theme which, in this case, is myzen.
    How to do it...
  3. Within this folder, rename the file STARTERKIT.info.txt to myzen.info.
  4. Open the .info file in an editor.
  5. Update the name field to the name of the theme which in this case is My Zen.
  6. Update the description field to My custom zen sub-theme.
  7. Save and exit this file.
  8. Open template.php in an editor and replace all occurrences of STARTERKIT_ with myzen using the find and replace all function.
  9. Save and exit this file.
  10. Repeat the above find and replace operation for the file theme-settings.php as well.
  11. Save and exit this file.

Visiting the theme administration page at admin/build/themes (Home | Administer | Site building | Themes) should now display our new theme. Screenshots, favicons, and other niceties can be configured just like for any other theme.

How it works...

The Zen theme contains a folder named STARTERKIT which is effectively a skeleton theme containing files and folders which can be readily customized to create a new theme. Once we have made a copy of this folder and renamed its .info file with the name of our theme, Drupal will recognize our new entry, which is now registered as a sub-theme of Zen as seen in the following screenshot.

Tip

While the Zen theme needs to be available, it does not need to be enabled for myzen to function.

How it works...

Once enabled, the front page of the site will look something like the following screenshot. It is worthwhile comparing the screenshots in this recipe with those from the Creating a theme from scratch recipe earlier in this chapter. The essential difference is that we have a slightly fleshed-out skeleton to work with when we use Zen with a lot of the right pieces already in the right place.

How it works...

There's more...

The Zen theme comes with a plethora of settings and documentation which can at times, be a little overwhelming. But the rewards of familiarizing ourselves with them are worth our time.

Sub-theme of Zen

We can confirm that this is a sub-theme of Zen via its .info file which specifies that

base = zen

As mentioned in the last chapter, if we need another theme similar to myzen, we can create one with base = myzen and save ourselves a whole host of repeated operations.

RTFM

Just about every folder which comes with Zen contains a README.txt file which is filled to the brim with copious documentation. It is a good idea to always read through these files. prior to diving in head-first

Rebuild theme registry automatically

The Zen theme contains a setting which rebuilds the theme registry automatically on every page load. This setting is exposed in the .info file as settings[zen_rebuild_registry] and also via the theme configuration page.