Currently only themes that are not belonging to a theming engine can have theme-specific settings. Engines can oly have engine-specific settings. I would like to have theme-specific settings for themes that are for theming engines.

CommentFileSizeAuthor
#2 patch_0.diff984 bytesthesaint_02

Comments

thesaint_02’s picture

Assigned: Unassigned » thesaint_02

To achieve this, insert the following lines after line 694:

//Template specific settings for theming engines
$settingsfile = $themes[$key]->path['dirname'].'/settings.php';
if (file_exists($settingsfile)) {
    include_once $settingsfile;
    $function = $themes[$key]->shortname .'_settings';
    if (function_exists($function)) {
        $group = $function();
        $form .= form_group(t('Theme-specific settings'), $group, t('These settings only exist for the %theme theme and all the styles based on it.', array('%theme' => $themes[$key]->shortname)));
   }
}

After that, you can put the file settings.php in your theme directory. If it contains the function [themename]_settings, the output of that function will be put after the engine-specific settings.

thesaint_02’s picture

StatusFileSize
new984 bytes

Here is the patch:

chrismessina’s picture

Can you give an example of what a settings file might look like? And how'd you'd access those settings the theme level?

TDobes’s picture

I see no reason why a theme engine could not implement theme-specific or even style-specific settings under the current system. It would merely be required to appropriately change the names of the variables it read/wrote from its _settings hook, then later read the appropriate variables when rendering the theme. I think this would work to accomplish your goal without requiring the use of an external file.

If you would like to use a settings.php file to introduce settings that are specific to your template-based theme, I feel a better place to introduce this functionality would be in a particular theming engine's _settings hook.

Also: Note that a theme can consist of BOTH a .theme file and template files. The .theme file merely needs to include the appropriate theming engine. Then the theme file could have its own _settings hook, while the theme would still be rendered using a theme engine. This also allows for overriding various themable functions that are not implemented by the theming engine... or even overriding the engine's rendering for certain themable objects. I've been meaning to write a page in the handbook regarding this capability, but never found the time. If you're interested, I'll write a short how-to here then use some copy/paste action to take it into the handbook.

thesaint_02’s picture

Yes, I would be very much interested in a sample .theme file that uses PHPTemplate. The way you describe it sounds much more un-kludgy than my modification to system.module.

I have one special question regarding this solution:
How does Drupal know which function to use? Do I have to wrap all templating calls I don't want to change? I mean like this:

function mytheme_page(){
  return phptemplate_page();
}
TDobes’s picture

To use a .theme file along with the phptemplate engine, place the following code at the top of your .theme file:


include_once('themes/engines/phptemplate/phptemplate.engine');
$theme_engine = 'phptemplate';
if (function_exists($theme_engine .'_init')) {
  call_user_func($theme_engine .'_init', $themes[$theme]);
}

/* define functions here... themename_functionname() */

Note that the code should be placed directly at the top of the .theme file, not inside a function. You can then define a themename_settings function for theme-specific settings. Note that, if the theme engine has any settings of its own, those settings will no longer appear. Therefore, you may want to call phptemplate_settings() from within your themename_settings() function. (concatenate its output on the end of your own settings)

The _settings hook, however, is a special case. For all themable functions, Drupal will check for the existance of functions in this order:
1. in the .theme file (themename_function)
2. in the theme engine (enginename_function)
3. the default function, defned in the Drupal module (theme_function)

thesaint_02’s picture

Thanks, this has solved my problem completely without hacking system.module.

Anonymous’s picture