A quick note about Zen for Drupal 7

The reason the instructions for creating a sub-sub-theme are so complicated is due to limitations and bugs in sub-theming in Drupal 6 core. Fortunately, all of these were fixed in Drupal 7 core, so no special instructions are needed for Zen 7.x-3.0 and later.

Before you begin

This document assumes you have already created a Zen subtheme based on the Zen STARTERKIT, as described in How to build your own sub-theme (6.x-2.x).

You should review Sub-theme structure and inheritance for an overview of how subthemes of subthemes inherit various elements from the direct parent (in this case, your subtheme) and the main ancestor theme (Zen).

Both Zen and the original subtheme need to be available in your sites/all/themes/ directory. Also note that your subtheme may not work properly until you have completed all of these steps. If you get errors after enabling your sub-subtheme, clear the theme cache and re-check to make sure you successfully made all of the changes listed below.

Note: These instructions are for Zen 6.x-2.x. You may need to modify them for 6.x-1.x themes.

Creating your subtheme

In the following example, sub is the machine name of your original subtheme, and subsub is the name of the new subtheme you are creating from sub. You need to replace these with the actual machine names of your themes.

Note: The sample commands in each step assume a Unix-like OS. Replace with the appropriate Windows-equivalent commands if you are using Windows.

  1. Create a new, empty directory in sites/all/themes with the machine name you want your sub-subtheme to have (subsub here). You will probably also want to create a css directory inside it.

    [drupal_root/sites/all/themes] $ mkdir subsub 
    [drupal_root/sites/all/themes] $ mkdir subsub/css
    
  2. Copy the .info file from your original theme into this directory and rename it for the new sub-theme:

    [drupal_root/sites/all/themes] $ cp sub/sub.info subsub/subsub.info
    
  3. Open this new file (subsub/subsub.info inside your themes directory) and edit the name and description for your new sub-subtheme:

    ; The name and description of the theme used on the admin/build/themes page.    
    name        = subsub
    description = Sub-subtheme of my Zen subtheme
    
  4. Change the base theme line to the name of your existing subtheme rather than zen:

    core       = 6.x
    base theme = sub
    
  5. Delete or comment all of the stylesheets lines. (Use a semicolon at the beginning of the line to make it a comment.)

    ; We want to inherit these stylesheets from the parent theme, so comment them out.
    ; stylesheets[all][]   = css/html-reset.css
    ; stylesheets[all][]   = css/filetype-icons.css
    ; stylesheets[all][]   = css/wireframes.css
    ; stylesheets[all][]   = css/layout-fixed.css
    ; stylesheets[all][]   = css/page-backgrounds.css
    ; stylesheets[all][]   = css/tabs.css
    ; stylesheets[all][]   = css/messages.css
    ; stylesheets[all][]   = css/pages.css
    ; stylesheets[all][]   = css/block-editing.css
    ; stylesheets[all][]   = css/blocks.css
    ; stylesheets[all][]   = css/navigation.css
    ; stylesheets[all][]   = css/views-styles.css
    ; stylesheets[all][]   = css/nodes.css
    ; stylesheets[all][]   = css/comments.css
    ; stylesheets[all][]   = css/forms.css
    ; stylesheets[all][]   = css/fields.css
    ; stylesheets[all][]   = css/graphic-overrides.css
    ; stylesheets[all][]   = css/inline-styles.css
    ; stylesheets[print][] = css/print.css
    
  6. Add a new line with an override stylesheet:

    ; Override the following stylesheets
    stylesheets[all][]   = css/style.css
    

    Note: Even if you do not wish to override your CSS, you must add at least one stylesheet in order for the parent theme's CSS to be inherited.

  7. Save the file.

  8. Now, create the style.css file you added to the theme. It can be empty.

    [drupal_root/sites/all/themes] $ touch subsub/css/style.css
    
  9. Copy template.php and theme-settings.php from the STARTERKIT into your new theme folder:

    [drupal_root/sites/all/themes] $ cp zen/STARTERKIT/template.php subsub/
    [drupal_root/sites/all/themes] $ cp zen/STARTERKIT/theme-settings.php subsub/
    
  10. Edit template.php. As you did when you originally created your subtheme, replace every occurrence of STARTERKIT with the new theme's name (subsub). (Use your text editor's find-and-replace functionality.)

    Additionally, change the hook_theme() to inherit hooks from your theme rather than directly from Zen. Change this:

    function subsub_theme(&$existing, $type, $theme, $path) {
      $hooks = zen_theme($existing, $type, $theme, $path);
      // Add your theme hooks like this:                                            
      /*                                                                            
      $hooks['hook_name_here'] = array( // Details go here );                       
      */
      // @TODO: Needs detailed comments. Patches welcome!                           
      return $hooks;
    }
    

    to this:

    function subsub_theme(&$existing, $type, $theme, $path) {
      $hooks = sub_theme($existing, $type, $theme, $path);
      // Add your theme hooks like this:                                            
      /*                                                                            
      $hooks['hook_name_here'] = array( // Details go here );                       
      */
      // @TODO: Needs detailed comments. Patches welcome!                           
      return $hooks;
    }
    
  11. Similarly, edit theme_settings.php and replace all instances of STARTERKIT with your new theme name (subsub). (Use your text editor's find-and-replace functionality.)

    Then, to make your sub-subtheme inherit the subtheme's settings, change the following line:

    include_once './' . drupal_get_path('theme', 'zen') . '/theme-settings.php';
    

    to:

    include_once './' . drupal_get_path('theme', 'sub') . '/theme-settings.php';
    

    And change this line:

      // Add the base theme's settings.                                             
      $form += zen_settings($saved_settings, $defaults);
    

    to:

      // Add the base theme's settings.                                             
      $form += sub_settings($saved_settings, $defaults);
    
  12. Save both files.

Your sub-subtheme is now ready for use and customization.

Customizing your subtheme

You can add new css to the style.css file you created earlier, or override specific stylesheets by adding a line for them in your .info file and creating a new stylesheet.

For example, to override page-backgrounds.css:

  1. Edit your subsub.info file to add or uncomment the following line:

    ; Override the following stylesheets
    stylesheets[all][]   = css/page-backgrounds.css
    stylesheets[all][]   = css/style.css
    

    Note: if the style.css you added earlier is empty and unused, you can remove it if you like once you override at least one other stylesheet.

  2. Copy the original file from your subtheme into your sub-subtheme's directory:

    [drupal_root/sites/all/themes] $ cp sub/css/page-backgrounds.css subsub/css/
    
  3. Edit the new copy of the stylesheet to override the parent theme's styling.

Templates are overridden in the same way as for your original subtheme, by copying the template into the new theme's directory and editing it. Note that if you wish to override (e.g.) node-page.tpl.php, you must copy both that file and the more generic node.tpl.php. See Sub-theme structure and inheritance for more information.

Comments

druojajay’s picture

Hi,

I followed these instructions multiple times, and got this error each time the sub sub theme was even sitting in my themes folder:

* warning: Invalid argument supplied for foreach() in /[...drupalpath...]/includes/theme.inc on line 485.
    * warning: Invalid argument supplied for foreach() in /[...drupalpath...]/includes/theme.inc on line 490.

Thinking it was something the matter with my existing subtheme, I recreated it from the STARTERKIT, and then recreated the sub-sub theme again.

I even installed a completely clean copy of Zen, to make sure I hadn't messed anything up there.

Same thing.

The fun really begins when I try to switch to the theme:


    * warning: Invalid argument supplied for foreach() in [..pathtodrupal..]/includes/theme.inc on line 485.
    * warning: Invalid argument supplied for foreach() in [..pathtodrupal..]/includes/theme.inc on line 490.
    * warning: Invalid argument supplied for foreach() in [..pathtodrupal..]/includes/theme.inc on line 485.
    * warning: Invalid argument supplied for foreach() in [..pathtodrupal..]/includes/theme.inc on line 490.
    * warning: Invalid argument supplied for foreach() in [..pathtodrupal..]/includes/theme.inc on line 485.
    * warning: Invalid argument supplied for foreach() in [..pathtodrupal..]/includes/theme.inc on line 490.
    * warning: array_map() [function.array-map]: Argument #2 should be an array in [..pathtodrupal..]/modules/system/system.module on line 1015.
    * warning: array_keys() [function.array-keys]: The first argument should be an array in [..pathtodrupal..]/includes/theme.inc on line 1817.
    * warning: Invalid argument supplied for foreach() in [..pathtodrupal..]/includes/theme.inc on line 1817.

Can anyone point me in the direction of fixing this issue?

xjm’s picture

Sounds like a problem with your stylesheets and scripts. Those lines are where core includes the stylesheets and scripts you've specified in your .info file. Check the format. It should look like:

stylesheets[all][] = css/style.css

Also, an aside, this article assumes Zen 2.x. Not sure how much of a difference it might make, but if you're using a 1.x theme, it might be related.

druojajay’s picture

Hi,

Thanks for the speedy reply. I had checked and double-checked that line, but maybe I was somehow missing something.

In the end, the only thing that worked was to start with a copy of the whole sub-theme, and then find-replace the machine name in the relevant files, then delete bits of the directory until I got back to the original point. I'm pretty sure that the code is exactly the same, but for some reason it works when nothing did when I repeatedly started from scratch.

In both cases, the exact same code was copied from sub.info into subsub.info.

If I'm a special case, then so much the better for everyone else, I guess. :) Hopefully my comment will help if anyone runs into a similar issue.

dru

rossmerriam’s picture

Hi there,
I'm getting the following error when I change the hook_theme() in step 10:
PHP Fatal error: Call to undefined function scratch_theme() in /user/name/Sites/site.com/sites/all/themes/sub_sub_theme/template.php on line 70

and in my template folder I've changed the code based on the steps, I think, to this:
/**
* Implementation of HOOK_theme().
*/
function sub_sub_theme(&$existing, $type, $theme, $path) {
$hooks = sub_theme($existing, $type, $theme, $path);
// Add your theme hooks like this:
/*
$hooks['hook_name_here'] = array( // Details go here );
*/
// @TODO: Needs detailed comments. Patches welcome!
return $hooks;
}

Any help would be greatly appreciated. Also my sub theme

xjm’s picture

"Undefined function" errors mean the code containing the function is not being included. Check the naming/identification of the parent theme in the .info, and make sure the directory structure is such that zen, the parent theme, and your new theme all reside directly in your themes directory. Also, try going through all the steps before you enable or use the theme.

You should consider asking in the forums, irc, or issue queues if you run into further problems.

rossmerriam’s picture

Thanks for the note. Your comment guided me in the right direction. My mistake was stupid, I forgot to change the base theme to my sub theme in my .info file. Problem Solved.

rossmerriam’s picture

Thanks for the note. Your comment guided me in the right direction. My mistake was stupid, I forgot to change the base theme to my sub theme in my .info file. Problem Solved.

drjonez’s picture

I had the same problem. Looks like I skipped #4 and didn't set a value for 'base theme = sub' in subsub.info

DaveyM’s picture

I found that when I copied the .info file from my original theme I was getting a bunch of php errors, such as

Invalid argument supplied for foreach() in (path to site)/includes/theme.inc on line 485.
Invalid argument supplied for foreach() in (path to site)/includes/theme.inc on line 490.
array_map() [function.array-map]: Argument #2 should be an array in (path to site)/modules/system/system.module on line 1015.
array_keys() [function.array-keys]: The first argument should be an array in (path to site)/includes/theme.inc on line 1817.
Invalid argument supplied for foreach() in (path to site)/includes/theme.inc on line 1817.

I commented out the following lines in the .info file:

;settings[zen_block_editing]        = 1
;settings[zen_breadcrumb]           = yes
;settings[zen_breadcrumb_separator] = ' › '
;settings[zen_breadcrumb_home]      = 1
;settings[zen_breadcrumb_trailing]  = 1
;settings[zen_breadcrumb_title]     = 0
;settings[zen_rebuild_registry]     = 1
;settings[zen_wireframes]           = 0

and it seemed to work ok after that. Haven't really spent any time looking into why, but I hope this helps someone ele.

David

Milkrow’s picture

David,
I had the same issue and tried your method and it seemed to fix things...to a point. What I did was start fresh first. I removed zen and my zen_subtheme from sites/all/themes and started over, step by step. I installed zen. I copied out the STARTERKIT folder and renamed it to my subtheme name and rebuild the registry (by visiting the theme list page). All was good. As soon as I changed the STARTERKIT.info.txt to subthemename.info I got the errors. So then I made the edit you prescribed by commenting out the default settings exactly as shown above. Then I rebuilt the registry again. Success. I could see the subtheme, enable it and voila. However, its not loading the CSS and I'm not sure why. Any ideas on next steps here?

LadyVanadis’s picture

Thank you so much for this page! The site I'm working on wants to allow users to change the theme, but each theme uses the same templates. Everything is working fine, except...

I've got a couple custom templates, such as user-profile-form.tpl.php, that is currently residing in the templates directory under my base sub-theme. Whenever I try to access it from one of my sub-subthemes (such as our fall version) I get this error:

warning: include(./sites/all/themes/adf_fall/templates/user-profile-form.tpl.php) [function.include]: failed to open stream: No such file or directory in C:\wamp\www\ADFDevelopment\drupal\includes\theme.inc on line 1066.

Which is completely accurate - the file doesn't exist there, it exists in the base theme (/sites/all/themes/adf_base/).

All of the custom forms are loaded through the adf_base template.php file using hooks - like this:

	$hooks['user_profile_form'] = array(
		'template' => 'templates/user-profile-form',
		'arguments' => array('form' => NULL),
	);	

How do I indicate that these should be read from the base subtheme and not the sub-subtheme? I've tried a couple options, and nothing seems to work. And I know its probably an easy fix - brain just can't find it :)

drjonez’s picture

drupal_root/sites/all/themes] $ cp sub/sub.info subsusb/subsub.info

should be

drupal_root/sites/all/themes] $ cp sub/sub.info subsub/subsub.info

in #2

xjm’s picture

Thanks :)

syntheticMedia’s picture

Hello,

First off thank you for these instructions. I have followed exactly and everything works great except one major problem:

On admin/build/block under the subsub tab, most (but not all) of my blocks are not appearing (if I go to the sub tab, the blocks do appear). So for example, under subsub tab, Navigation, primary Links and most (but not all) views blocks are not available to put into regions.

In other words the blocks simply dont appear, basically most any block that is being used in sub theme are not available in subsub theme. I tried disabling one of the blocks in question at sub to see if it was made available to subsub, tried flushing cache all the usual stuff, but no luck.

EDIT- I also notice that my logo is not appearing ( i have it set to use default logo, works fine in sub, no at all in subsub)

Suggestions?? Please advise, thanks!

syntheticMedia’s picture

If anyone has the same problem, I found the solution here http://drupal.org/node/351217#comment-1785210