How to build your own sub-theme (5.x)

Last modified: July 14, 2008 - 20:58

The base Zen theme is designed to be easily extended by its sub-themes. You shouldn't modify any of the CSS or PHP files in the root zen/ folder; but instead you should create a sub-theme of zen which is located in a folder within the root zen/. For example, the zen/zen_classic folder contains the files for the Zen Classic sub-theme.

  1. Copy the STARTERKIT folder and rename it to be your new sub-theme. IMPORTANT: Only lowercase letters and underscores should be used.

    For example, copy the zen/STARTERKIT folder and rename it as zen/foo.

  2. If you want a liquid layout for your theme, copy the layout-liquid.css from the zen folder and place it in your sub-theme's folder. If you want a fixed-width layout for your theme, copy the layout-fixed.css from the zen folder and place it in your sub-theme's folder. Rename the layout stylesheet to "layout.css".

    For example, copy zen/layout-fixed.css and rename it as zen/foo/layout.css.

  3. Copy the print stylesheet from the zen folder and place it in your sub-theme's folder.

    For example, copy zen/print.css to zen/foo/print.css.

  4. Copy the zen stylesheet from the zen folder and place it in your sub-theme's folder. Rename it to be the name of your sub-theme.

    For example, copy zen/zen.css and rename it as zen/foo/foo.css.

  5. Edit the template.php and theme-settings.php files in your sub-theme's folder; replace ALL occurances of "STARTERKIT" with the name of your sub-theme.

    For example, edit zen/foo/template.php and zen/foo/theme-settings.php and replace "STARTERKIT" with "foo".

  6. Log in as an administrator on your Drupal site and go to Administer > Site building > Themes (admin/build/themes) and enable your new sub-theme.

    Optional:

  7. Modifying Zen core stylesheets: If you decide you want to modify any of the other stylesheets in the zen folder, copy them to your sub-theme's folder before making any changes. Also, be sure to edit the drupal_add_css() calls near the beginning of your sub-theme's template.php file.

    For example, copy zen/html-elements.css and rename it as zen/foo/html-elements.css. Then edit zen/foo/template.php and change drupal_add_css(path_to_theme() .'/html-elements.css', 'theme', 'all'); to drupal_add_css(path_to_subtheme() .'/html-elements.css', 'theme', 'all');

  8. Modifying Zen core template files: If you decide you want to modify any of the .tpl.php template files in the zen folder, copy them to your sub-theme's folder before making any changes.

    For example, copy zen/page.tpl.php to zen/foo/page.tpl.php.

  9. Themeing Drupal’s search form: Copy the search-theme-form.tpl.php template file from the zen folder and place it in your sub-theme's folder. In your sub-theme's template.php file, un-comment the phptemplate_search_theme_form() function.
  10. Further extensions of your sub-theme: Discover further ways to extend your sub-theme by reading Drupal's Theme Developer's Guide online at: http://drupal.org/handbooks

How to replace strings in a file

Solipsist@drupal.org - June 4, 2008 - 20:42

Easiest way to do it provided you got Linux or *NIX derivative OS (Mac OS X included):

sed "s/STARTERKIT/name_of_your_subtheme/g" template.php > temp; mv temp template.php;
sed "s/STARTERKIT/name_of_your_subtheme/g" theme-settings.php > temp; mv temp theme-settings.php;

or

xurizaemon - December 5, 2008 - 22:10

perl -pi -e 's#STARTERKIT#yourthemename#g' *

Multi-site install?

naught101 - November 7, 2008 - 07:17

How does zen work with multi-site installs? I would like to create sub-themes that are not availableto all sites, but restricted to one of the multisites. Is it possible to have the core zen files in /sites/all/themes/zen, and a subtheme in /sites/sitename.com/themes/zen/subtheme, where /sites/sitename.com/themes/zen/ is empty?

If not, are there problems with installing two copies of zen, one for all sites, and one for the restricted sub-theme? Or do you recommend simply not installing zen in /sites/all/themes?

Multi-site on D5

xurizaemon - December 5, 2008 - 22:08

This issue seems to be resolved on Drupal 6 - I didn't even realise it existed until I tried to duplicate my D6 procedure on D5.

I see you figured out a workaround after raising the issue here - http://drupal.org/node/256011

Would be good to have other methods (eg a working symlink setup?) suggested. While your solution of hosting multiple Zen installs is reported to work, it does mean having multiple copies of the same code on your system, so adds maintenance requirements.

Interested too

kardave - November 14, 2008 - 18:55

subscribing

STARTERKIT.info change...

vmoya - November 18, 2008 - 23:48

On my zen configuration I made the changes as on the instructions provided but I did not see my sub-theme on the list in drupal. I had to make some changes to the STARTERKIT.info file on my new sub-theme folder and renamed it first from STARTERKIT.info to something.info. Once I did that, then I edit the .info file on the very top were it says "name = Zen Themer’s Starter Kit" change it to "name = something" and then I was able to see my theme on the list in drupal. Also make sure you change all the instances in this .info file like on the template.php and theme-setting.php files.

Still working on this and hope to make it into a nice production site.

MY BAD

vmoya - November 18, 2008 - 23:49

POSTED ON THE WRONG PLACE CHECK OUT THE 6.X VER

SORRY

 
 

Drupal is a registered trademark of Dries Buytaert.