[themes] add color choices to theme and insert a css
Tracey Hummel
thummel at email.arizona.edu
Mon Nov 9 23:36:30 UTC 2009
I got this to work using this in my template.php file:
$banners = theme_get_setting('banners');
switch($banners) {
case ("white-gray"):
drupal_add_css(path_to_theme() . '/white-gray.css', 'theme',
'all');
break;
case ("blue-gray"):
drupal_add_css(path_to_theme() . '/blue-gray.css', 'theme', 'all');
break;
default:
drupal_add_css(path_to_theme() . '/red-blue.css', 'theme', 'all');
break;
}
And this in my theme-settings.php file:
<?php
function graphicDesign_settings(&$saved_settings) {
$defaults = array(
'banners' => 'red-blue',
);
$settings = array_merge($defaults, $saved_settings);
$form['banners'] = array(
'#type' => 'select',
'#options' => array(
'red-blue' => 'Red/Blue',
'blue-gray' => 'Blue/Gray',
'white-gray' => 'White/Dark Gray'),
'#default_value' => $settings['banners'],
'#title' => t('Choose a Banner Color Combination'),
);
return $form;
}
Quoting Brent Hardinge <brent at hardinge.net>:
> Tracey,
>
> It seems that in order to get the css into the system, you need to use
> drupal_add_css outside of the preprocess function because it is the
> template_preprocess_page function that is used to add the css to the
> $variables['styles'] function.
>
> So what I would recommend doing is adding the following at near the
> top of your template.css file:
>
> drupal_add_css(path_to_theme() . '/' .theme_get_setting('banners')
> .'.css', 'theme', 'all');
>
> That should replace your switch function and print the appropriate css
> file based on the settings.
>
> Cheers,
> Brent
> ---------------------------------------------------------
> Design / Interaction / Strategy
> http://brenthardinge.net
> ---------------------------------------------------------
>
>
>
> On Mon, Nov 9, 2009 at 10:00 AM, Tracey Hummel
> <thummel at email.arizona.edu> wrote:
>> My trying a add page preprocess that will allow site administrators
>> to be able
>> to configure a theme and choose different banners/color
>> combinations. Based on
>> what they select, a different css file would be added that would modify the
>> banners graphics/colors.
>>
>> I added three choices to the theme's configuration page by adding
>> this to the
>> theme-settings.php file:
>>
>>
>> function graphicDesign_settings(&$saved_settings) {
>> $defaults = array(
>> 'banners' => 'red-blue',
>> );
>> $settings = array_merge($defaults, $saved_settings);
>>
>> $form['banners'] = array(
>> '#type' => 'select',
>> '#options' => array(
>> 'red-blue' => 'Red/Blue',
>> 'blue-gray' => 'Blue/Gray',
>> 'white-gray' => 'White/Dark Gray'),
>> '#default_value' => $settings['banners'],
>> '#title' => t('Choose a Banner Color Combination'),
>> );
>> return $form;
>> }
>>
>>
>> In the template.php file, I'm trying to use the variable passed to add a css
>> file based on what they select. In the template.php file:
>>
>> function graphicDesign_preprocess_page(&$vars) {
>> $banners = theme_get_setting('banners');
>> drupal_set_message(print_r($banners,true));
>>
>> switch($banners) {
>> case ("white-gray"):
>> drupal_add_css(path_to_theme() . '/white-gray.css', 'theme', 'all');
>> break;
>> case ("blue-gray"):
>> drupal_add_css(path_to_theme() . '/blue-gray.css', 'theme', 'all');
>> break;
>> default:
>> drupal_add_css(path_to_theme() . '/red-blue.css', 'theme', 'all');
>> break;
>> }
>> }
>>
>> The css is not being added. Is anyone doing something similar and would be
>> willing to help me?
>>
>> Thanks,
>> Tracey
>>
>> --
>> Tracey Hummel
>> Web Developer
>> University Information Technology Services
>> Learning Technologies Services
>> University of Arizona
>> (520) 626-5139
>> tracey at uainfo.arizona.edu
>>
>>
>>
>>
>>
>> _______________________________________________
>> themes mailing list
>> themes at drupal.org
>> http://lists.drupal.org/mailman/listinfo/themes
>>
More information about the themes
mailing list