Theme setting to change colours

Events happening in the community are now at Drupal community events on www.drupal.org.
tinarey's picture

Hi there,

I'm currently working on an Omega subtheme with a settings tab that allows it to change the colors of the theme; like an inbuilt, more modern and more lightweight Color module. However I'm stuck at a point where I'd need to make sure upon enabling the theme that a color.less (LESS css preprocessor, awesome stuff!) file exists somewhere...

• option 1: putting the colors.less into the theme's css directory; would be my preferred solution for it would all be in one place. However I can't figure out how to save files to another directory than in one of the stream wrappers (like public://). Have tried writing a stream wrapper but that didn't work out (because of the limited hooks available from within a theme?)

• option 2: putting the colors.less somewhere under public:// is probably the cleaner, more "drupalesque" way but I'm running into two issues here: first I'm not sure how to safely load it from within global.less (which I would have to do to have all the less variables from colors.less available). Of course I can do
import "../../../../default/files/color_settings/css/colors.less"; but that doesn't look right at all. What if anything doesn't sit where I have it?
And second how can I make sure that colors.less is there/gets created when my theme gets enabled? I've googled my ass of, but couldn't find a hook or anything for that o.O Am I blind?

Or is it not a good idea at all to have it inbuilt? I just thought this for a base of premium themes that just have to be downloaded with omega; enable and go, without installing and configuring heaps of other modules. Could I write a module included and enabled with the theme anyhow? (Without install profiles or make files – I thought making it almost as easy for them as Wordpress). Any hints thoughts on this would be greatly appreciated!

Cheers, Tina

Comments

Did you check

Argus's picture

Did you check http://drupal.org/project/less and try to use that?

Thanks Argus, I'm using this,

tinarey's picture

Thanks Argus, I'm using this, works like a charm. My problem is not processing the file but where to store the file programmatically...

Is the files_directory_path() relevant?

drew reece's picture

Check the notes at the bottom of the page for the Drupal 7 method.
http://api.drupal.org/api/drupal/includes--file.inc/function/file_direct...

I'd have a look at the examples module http://drupal.org/project/examples should have something that could help within the file-example or the files module code.

I guess you would use an install hook to write a default file to the files/your-less-stuff/ but I'm not sure that you can do that from a theme.

Check out hook_enable & hook_install in the api docs http://api.drupal.org

Solved :)

tinarey's picture

After reading through the whole file example and finally realizing that the Omega Tools module is able to save stuff in the theme folder I just copied from there and it works :) (Actually the bit that helped me is so easy that I really wonder why I couldn't get it to work before...o.O ) Now I can keep the colors.less file within the theme (including a default file) and don't have to check its existence when the theme is enabled.

Thank you guys!

Your post made me finally get

drew reece's picture

Your post made me finally get around to trying .less
It's really good :) cheers.

I use it with less.app on Mac OS, it just processes the .less on save files & overwrites the css in the theme folder, nice.

Omega Framework

Group organizers

Group notifications

This group offers an RSS feed. Or subscribe to these personalized, sitewide feeds: