tags:

views:

50

answers:

3

I am going to start on a website whose requirement is to change the color scheme after every 2 weeks.

I am looking for a dynamic solution to change colours and somewhat structure of a website using css & php.

One solution which i can see is using dynamic css method for example

<?php
header("content-type: text/css");
$mencolour = "#ff0000";
echo 'h1 {color:$menucolor}
?>

Other solution is using some php classes to do the same task. such as one is available on phpclasses website. http://www.phpclasses.org/package/6482-PHP-Parse-and-process-Leaner-CSS-files.html

Is there any other better way of doing this? if any one has used above two methods, what could be drawbacks of using them.

Need some expert opinions :)

+2  A: 

Sass is a popular CSS pre-processor that, among other things, lets you use variables in CSS, for things like your color scheme. You'd compile the CSS when you change it, so no need for the overhead of running a PHP script each time it loads. (Yeah, you could write your own cache system for that in PHP, but no need to redo others' hard work ;D)

$menu-color: #123456;

#menu { color: $menu-color; }
Matchu
Ghost
@Ghost — To be clear, it's not something that has to be installed on your server: you just run it on your home computer before you push the site live, and it produces a completely static `.css` file. Is there a particular issue with installing Ruby (which Sass runs on) on your development box?
Matchu
A: 

You can use a body class to change the theme:

/* Base style */
h1 { color: grey; }

.spring h1 { color: green; }
.summer h1 { color: yellow; }
.fall   h1 { color: orange; }
.winter h1 { color: blue; }

To change the theme, just add the class on the body:

<body class="fall">
  <h1>The leaves are falling!</h1>
</body>
Andrew Vit
A: 

Given that this is on a 2-week schedule, firing off a dynamically generated css file is overkill. It would be far easier to serve up a static .css file, which can be generated by PHP. That way you don't have to mess with outputtting cache headers and whatnot - the file will be cached the way any other static file would.

Use cron a similar timed-job tool to rebuild the .css file whenever you need those color changes to occur.

The PHP method, by default, would cause the clients to re-query the server for changes on every hit. That's a waste of bandwidth and cpu time just to change a few values once every 14 days.

Marc B