Sub-themes, their structure and inheritance

Sub-themes are just like any other theme, with one difference: They inherit the parent theme's resources. There are no limits on the chaining capabilities connecting sub-themes to their parents. A sub-theme can be a child of another sub-theme, and it can be branched and organized however you see fit. This is what gives sub-themes great potential.

sub-themes and dependancies

Imagine starting with a base theme designed as wireframes, then applying and refining all the details from a sub-theme. Then, off the same wireframe, testing out alternate designs by branching out another sub-theme. Working on a multi-site installation but you need a cohesive look and feel? With sub-theming, a lot of the design resources can be shared. Site-specific changes can be set to a specific sub-theme, but any shared resources can be edited once to be applied across all the installations. With careful planning, the possibilities are endless.

To declare a parent or "base theme", set this inside the sub-theme's .info file," themeName" being the internal name of the parent theme:

base theme = themeName
 

The following are inherited:

  • All style sheets defined in the parent theme, but there is an option so this can be controlled.
  • All JavaScripts defined in the parent theme.
  • All template (.tpl.php) files.
  • Anything defined from the "template.php" file. This includes theme function overrides, preprocessors or anything else. Each sub-theme will include its own template.php file along with the one provided by its parent.
  • Screen shot for the parent theme as long as the .info file uses the same settings from its parent.

The following are not inherited:

  • logo.png set for the theme. This does not include uploaded logos, since they will always be used.
  • Some of the settings set within the .info file. This includes regions. If you are not using the default regions, then make sure your "page.tpl.php" file for the sub-theme matches what is set for regions in the .info file. Each base and sub-theme can have their own region settings.
  • Anything set within the "theme-settings.php" file for the advanced theme settings.
  • Anything set within the "color" directory for color.module support.

Note that sub-themes can be placed outside of the base theme's directory or within it. Before version 6, they had to be in the sub-directory of the parent theme.

themeName

SigiReimann - April 28, 2008 - 09:56

What I experienced is: the themeName is the name of the .info file. It seams to me that the name assigned int he "name = [name]" clause cannot be used as a reference for the base theme, but it appears in the administrators page for activating the theme. On the other hand in the users profile the name of the .info file is displayed.

So it seams a good idea to have the same name in both places, but if you don't it may be somewhat confusing.

I would recommend to change this in Drupal and use one name in all places.

sigi reimann

Separate names are good

wdmartin - June 29, 2008 - 10:28

Having two names for the same theme can make it slightly more confusing for theme developers. However, there's a good reason for it. Drupal uses two names for one theme to make it less confusing for the end users by making it possible to use spaces (and other user friendly characters) in the theme administration pages.

Suppose I have a theme named "Corporate Chic". Because Drupal uses the internal name of the theme as a variable name, it has to conform to the PHP variable naming conventions, which prohibit spaces and most punctuation. We'd have to use either "CorporateChic" or "Corporate_Chic" as the theme name. The first is hard to read, and the second is ugly. Neither one will look good in the themes administration page. But prior to Drupal 6.x, that's exactly how the theme names appeared to the end user - either with no spaces, or with underscores taking the place of spaces.

A somewhat larger issue has to do with internationalization. PHP variable names are limited to ASCII characters (from 127-255 in the ASCII table). If you're writing a theme for use in a Finnish web site, for example, you'll need to change "Väestö" to "Vaesto", which makes it less familiar to Finnish readers and may change its meaning. In German, what do you do about the eszett character? (That's the ß character.) And heaven forbid that you ever try writing a theme in Japanese, Chinese, or any other language written with ideographs.

Splitting the theme name in two lets us get around all that. The INTERNAL theme name (derived from the file name of the info file, e.g. corporate_chic.info) can follow the PHP variable guidelines, whereas the EXTERNAL name of the theme can include spaces, punctuation, and non-English characters. The internal name gets used in Drupal's execution; the external name just serves as the label that the Drupal administrator sees in the administration pages.

So yes, the split makes it slightly more confusing for developers making sub-themes. On the other hand, developers will figure out the difference, and there are many fewer developers than there are end users. It's a good trade-off, and considerate to the end users.

A big thing to point

rainer_f - July 28, 2008 - 09:08

A big thing to point out:

Since D6, sub-themes must not reside within subdirectories.
This feature make it's possible to have sophisticated sub-theming on MULTISITE installations.
Great!

Rainer
Professional Drupal services for Germany
http://www.feike.biz

 
 

Drupal is a registered trademark of Dries Buytaert.