views:

36

answers:

4

A web designer has created a design for our Drupal web site which requires a different color scheme for various sections of the site. Drupal does not support this design requirement by default.

Currently I am using JavaScript to change the color scheme based on the page title. After adding some content pages I now realize that this is a terrible way of doing things. I need some ideas for a better way of changing the color scheme depending upon the content.

Is there a way to apply a different theme to a page based on its node value? I could create a slight variation of my theme for each color scheme, although that makes theme maintenance more difficult.

I've also thought about using CCK to add a field to my page content type and then changing the color scheme based on that custom field. This would eliminate the need to add code to my JavaScript for every new page.

Or is there a module for changing color schemes per page?

A: 

You could add some css in hook_preprocess_page function based on node or other criteria and add the css in the page template as embedded styles.

The idea will be the same as doing it in JavaScript, but you will have php, drupal etc available to do what you need. It should be a lot easier since you can test the node type, or a value you set on the node object.

googletorp
+1  A: 

You might want to take a look at the ThemeKey module, which allows you to determine which theme is used based on conditions like node type or path.

Dave Reid
I'll mark this as the answer, but I actually used the Sections module because that is how the pages / nodes are organized.
rsrobbins
A: 

The CSS module does node-specific CSS, so you could use that to adjust colors.

Scott Reynen
A: 

I would suggest implementing hook_preprocess_page in your theme, and applying a body class based on the node type (or types) being displayed. Or, potentially, put these classes in the node's preprocess for display. So, for instance, if you're viewing a 'project' node, put:

<body class="... node-type-project">...

Then the designer can target styles based on which classes the body has. This is fairly easy to automate, just do a "node-type-". strreplace("_", "-", $node->type) to change any future node type into a class, which you then feed into either the body or the node.

John Fiala