By arnoldc on
I would like to setup some database values that can be applied to the styles. I would like to do something like that in style.css. Can I make Drupal to process a style.php file?
body{
background-color:#<?php print $background_color; ?>;
}
.homeblocks {
margin:0;
width:200px;
height:100px;
background:url(images/<?php print $block_color; ?>/block.gif) no-repeat;
}
Comments
You could checkout
You could checkout Awesomengine.
http://drupal.org/project/awesomengine
Yes, but it is expensive.
Yes, but it is expensive. For one the css is no longer cached by the browser so it gets reloaded on each page view. It also takes some time to generate the css this way.
A couple of alternatives are
1) Use fixed class names in style.css and apply the approriate css class to the elements (in this case body and .homeblocks). So you would have rules in style.css like
2) Another approach is to us inline styles in page.tpl.php (or other template file), for example
Yes you can
first of all you need create a page like style.css.php and define all that dynamic stuff in it and tell drupal to include that file ass css by adding this code to your theme info file
If your css files are not so "dynamic" I mean if colours defined in theme settings (check theme settings api module) and does not need to be changed untill you update theme settings everything will be fine. Theme minimizing options will work fine but if you need more dynamic thing say color will change depending on time instead of adding CSS files at info file try adding them at page.tpl.php file
php in stylesheet
You cannot embed php code in a css file. You could do what you want by embedding the style information in the header in your page.tpl.php file. You could also insert and inline style in the affected element. eg.
Thanks to all the responses.
Thanks to all the responses.
After exploring further, I realize none of these approaches would work for me since I also have to deal with WYSIWYG editing.
To simplify matter, I need to keep all CSS intact as the editor is linking to the same CSS file. Instead, I create a set of folders (each contains the same set of images but with different colors). The admin is responsible to copy the desired color folder to the current color folder. Not user friendly but will get the job done for now. In the further, I probably have to write a module to automate the copying process whenever a new color theme is picked.
From this comment I suspect
From this comment I suspect you want to check out Integrating color module
Yes the core color module
Yes the core color module seems pretty neat. I am not a graphic designer and I don't want to over-haul the current templates. Thanks anyway.
...
http://drupal.org/project/color_soc08 will do what you want precisely if I understand you correctly. Right now its in heavy dev but not so long ago I did pretty much what you are doing with an older version.
Its light years on from core color module and allows you to use color "tags" (as many as you want), which gives you dynamic color replacement.
Pimp your Drupal 8 Toolbar - make it badass.
Adaptivetheme - theming system for people who don't code.
yes, just edit .htaccess
Add these two lines to your root .htaccess file:
You don't have to add .php to the end of your css file, because this tells php to preprocess your css.
Then you can add php to your CSS file in your theme like this: