Dynamic CSS Files in Drupal

Dave Cohen's comment on Nick Lewis' recent post got me to thinking about the power of serving a dynamic CSS file. To quote:

I don't know why themes don't use PHP to define styles. I've started to define a style.php instead of a style.css. This way, I define all the colors near the top of the file, and use PHP to refer to the variables later.
You have to put this in style.php:
header("Content-type: text/css");

And this in your template.php (if using phptemplate engine):

That's a great trick. Using some variations on this trick, one could create a Drupal module/theme combo that would allow less technical administrators to modify style information through a form in the admin menu. Administrators could have a form where they could enter hex color codes for things like body background, links, hovering over links, block titles; font size for h1, h2, h3, etc.; alignment, border color and width -- all of these would be great for creating a quick, customized site without too much technical knowhow.

A more technical, but more flexible solution is to just allow users to edit the CSS in a textarea (a la Movable Type's template system). However, although I don't want to limit creativity, I still like the idea of a multiple choice and/or guided theme customization process.

Both of these methods have the advantage of being able to view changes immediately and therefore administrators can experiment with different settings easily. Stick in some pop-up color pickers, some image uploading, font-family pickers, and the ability to position things on the page and we'll really have something to offer non-developers who want to tap into the wealth of features offered by Drupal without feeling like they're getting a "canned" site.

Published in:

Get in touch with us

Tell us about your project or drop us a line. We'd love to hear from you!