How to change CSS with page attributes

Permalink
Hi,

Been searching and searching ant there are solutions to change some elements (for example the background images) by using page attributes.

But that is not quite what I am looking for.

I've been constructing site for one of our clients. The site structure includes three different main sections (three different themes) and several templates (in two finished themes/sections) already.

The last part of the site is killing me. It looks like that the number of templates is about be so huge it won't be a happy solution for anyone.

1) All we need is basically ONE page layout (all the elements are in the same place on every page)

2) however, different (sub)pages must be displayed in different color (menus, header images, mouse hovers, links etc). Previously I solved this by creating template and css for every color. VERY frustrating and expensive to maintain.

So, that is really not an option. With Concrete 5, I'd like solve this by using page attributes: I'd have only that one template but many CSS files. With Custom Attribute selection, I'd choose which CSS to use. How do I proceed?

I've:

- Created a new theme and installed required template(s)
- Added Custom Attribute field to this template. Let's say that the options are "red", "green" and "blue"
3) Created three different css files: "red.css", "green.css" and "blue.css"

 
mesuva replied on at Permalink Best Answer Reply
mesuva
Try chucking this in your header.php file, perhaps just underneath your core stylesheet(s):

<?php
$scheme = $c->getCollectionAttributeValue('colorscheme');
if ($scheme) { ?>
<link rel="stylesheet" media="screen" type="text/css" href="<?php echo $this->getThemePath()?>/<?php echo $scheme; ?>.css" />
<?php } ?>


Where colourscheme is the name of your page attribute. You'd just put in 'red', 'green', etc as the options, which matches the names of your extra stylesheets (no .css)

I may have a typo in the above as I just typed it directly in without testing it, but the idea should be sound I believe.
ollijarvinen replied on at Permalink Reply
Thank you sooo much! Works like a dream.
mesuva replied on at Permalink Reply
mesuva
Great to hear, happy to help.

Would you be able to do a 'Mark as Best Answer' on my post? :-)
TeKnoZiz replied on at Permalink Reply
TeKnoZiz
I just used it as well, works great! Thanks.