I got it working marvelously for my top level theme but I want to make sub-themes (for different sites and so forth). I was thinking that I should copy the .theme file to the sub-theme folder and then maybe include the parent .theme file and call a common function that creates the settings form but this seems clunky.

Would it be possible to make this automatic in 5.1 or are you just waiting for 6.0 to come out and I should just deal with it till then? (it will be doing it 6.0 right?)

Comments

JohnAlbin’s picture

Title: Support in sub-themes » Better support for sub-themes
Assigned: Unassigned » JohnAlbin
Category: feature » bug

The Custom Theme Settings API has been updated for inclusion in Drupal 6 and I will be backporting the D6 API for Theme Settings API 5.x-2.0. So let me briefly describe how phptemplate sub-themes will work in Drupal 6:

  • Drupal 6 will have .info files for themes which will make sub-themes easier (and they won’t have to be subdirectories of the main themes.)
  • Any file in the main theme’s directory will be used unless that filename exisits in the sub-theme’s directory. For example, sub-themes without template.php files will use the main theme’s template.php. Sub-themes with template.php files will NOT automatically have access to the main theme’s template.php; they will have to include that file if they want its functionality.
  • (Not yet committed to D6. See #57676) Custom Theme Settings will be called from THEMENAME_settings() or phptemplate_settings() functions inside the template.php file.

I’m going to mark this lack of non-clunky sub-theme support as a bug. It will be fixed in 5.x-2.0.

The method you describe, Alexander, is probably the best way to do it with the 5.x-1.0 version of the module.

To make migration to 5.x-2.0 easier, I would do the following:

In the maintheme.theme file, write:

function common_settings($settings) {

  // Set the default values for the theme variables
  $defaults = array(
    'example_credits' => 1,
  );

  // Merge the settings and their default values
  $variables = array_merge($defaults, $settings);

  // Create the form using Form API
  $form['example_credits'] = array(
    '#type' => 'checkbox',
    '#title' => t('Show credits'),
    '#default_value' => $variables['example_credits'],
  );

  // Return the form
  return $form;
}
function maintheme_settings() {
  // Pass the saved theme settings
  return common_settings(theme_get_settings('maintheme'));
}

In the subtheme.theme file, write:

include "../maintheme.theme";
function subtheme_settings() {
  // Pass the saved theme settings
  return common_settings(theme_get_settings('subtheme'));
}

And then when 5.x-2.0 comes out you can nix the maintheme_settings() and subtheme_settings() and rename common_settings() to phptemplate_settings() and move it into maintheme’s template.php file.

cpill’s picture

Thanks for that. i had problems including the parent themes .theme file. Could not be found. Then I realised that the theme I'm making doesn't require sub themes as in the themes settings you will be able to select CSS files to include from a sub folder, which pretty much makes the need for sub themes redundant.

I'm trying to make a "one-theme-to-rule-them-all" CSS Zen garden style so I don't have to keep changing markup and it can be configure by the less techy people in the company who just know a little CSS. Hopefully the more sites we use it on the bigger the CSS library will grow and the less work will be needed to do design.

I look forward to seeing your improvements in 5.x-2.0 and in 6.0!

p.s. I wanted to add some options for a variable number of settings i.e. I wanted to be able to select a CSS file based on module type or if its the front page etc. Can you store an Arrays as a setting value?

JohnAlbin’s picture

A lot of people have their own Sauron-inspired, CSS-Zen-Garden-like theme. I’ve got one, too! Good luck; it’s doable.

About your P.S.:

The THEMENAME_settings() function just uses FAPI. So it would depend on what form widget you used. If you had a multi-value select box or series of checkboxes, I believe it will store those values as an array.

hass’s picture

let me subscribe here... and say something to the currently so called "bug".

I've build a theme with ~20 subthemes. all themes have their own theme file, while they sometimes have different settings. The thing you are trying is a general problem until you do not have a page.tpl.php in your subtheme directory... if you have this problems i'm sure you do not have a page.tpl.php in the subtheme directory, isn't it? Therefor all the main theme *.tpl.php files are used while you have a "CSS only subtheme"...

To solve this problem you must create a page.tpl.php in D5. You can include the main files... but you need the page.tpl.php file. After this step you get what you want. Have a look to my yaml theme package... check out and see how to workaround this general theme engine problem in D5.

This is not a bug of this module... it's an unimplemented feature of theme engine in drupal core! i think this should be set to "won't fix" for 5.x or postponed to D6.

cpill’s picture

Thanks hass,

I'm not sure I follow you (or you me) but the idea was to not have a different page.tpl.php file as any changes to the HTML would mean the layout CSS would stop working. I originally thought I needed to make sub-theme folders to work within the Drupal theme system, but then I realise that my idea circumvented the need to work within this system.

With this in mind you could actually create a page.tpl.php file that used the CSS Zen Garden structure exactly and then use the Theme Settings module to select any of the CSS Zen Garden styles. Your not allowed to use the designs outside of their site but any of them could be a good starting point for your own design (i.e. change the background images keeping the exact sizes used in the original, maybe tweek the colours and your away).

I might have a go at it at some point. I will put my theme up for the general public and invite people to contribute to the CSS archive once I have created some CSS templates that address markup structures that are created within the theme.

The original bug report was that if you create a set of theme settings, they don't show up when editing the sub-themes settings page, which I would say was a bug, but its going to be rectified.

hass’s picture

Spend some time on "YAML for Drupal" Theme http://www.yaml-fuer-drupal.de/de/download, please. I've done what you are trying, but you cannot get out with a CSS only subtheme without a page.tpl.php (+ node.tpl.php files and others) in the subfolder of a main theme. i've included the main theme files (for e.g. node.tpl.php) except page.tpl.php and you can take the idea out of my themes...

I know this is not what a theme developer expect. I hoped this is different when i started over, but it wasn't. If you'd like to get this working in a supported Drupal way you need to go the way i used or alter Drupal core. I think you don't like the last way and if you don't like the way i used - it may be unsupported.

Maybe there is another Drupal way (i'm not aware about), but nevertheless there is no need to change the module to support something Drupal themself do not support!

JohnAlbin’s picture

Project: Theme Settings » Theme Settings API
Version: 5.x-1.3 » 5.x-1.4
cpill’s picture

Not really sure what your on about Haas, but the trick is in the way you organize your style sheets. One for Layout, one for Fonts etc. Site specific stuff, like images or CSS tweeks can be in their own folder. Image references are relative to the CSS file so an /image folder in the same folder the CSS file is in will work and keep the CSS simple.

IF you need to alter the tlp.php files you can but woun't be reusable, but if they are small changes per site I guess its no biggy.

word

JohnAlbin’s picture

Version: 5.x-1.4 » 5.x-2.0-rc1
JohnAlbin’s picture

Status: Active » Closed (won't fix)

It now seems unlikely we need to fix this.