I am working to create a radio button list in the CMS on every page so that an option can be selected that will change the CSS files that are used according to which button is selected.
For example my list is a simple list of colour options, eg. Green, Blue, Red etc
I would like the user to have the option to select a set of css rules by simply clicking one of the radio buttons in the CMs for each page.
This means that one page could be green, and another could be blue and another could be red etc.
I have successfully developed the list of radio buttons which appear correctly on every page, by including the code below on my page.php
<CODE>
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new OptionsetField(
$name = "CSStheme",
$title = "CSSthemes",
$source = array(
"1" => "Green",
"2" => "Blue",
"3" => "Red",
"4" => "Pink",
"5" => "Orange",
"6" => "Yellow",
"7" => "Black"
),
$value = "1"
));
return $fields;
}
</CODE>
This creates the list in my CSS on every page because it is on the page.php, which is being used as the base for all my pages.
The second piece of code that I have is below.
<CODE>
class Page_Controller extends ContentController {
public function init() {
parent::init();
if($this->CSStheme == '1'){
Requirements::css("mysite/css/greenlayout.css"); Requirements::css("mysite/css/greentypography.css");
}
if($this->CSStheme == '2'){
Requirements::css("mysite/css/bluelayout.css"); Requirements::css("mysite/css/bluetypography.css");
}
if($this->CSStheme == '3'){
Requirements::css("mysite/css/redlayout.css"); Requirements::css("mysite/css/redtypography.css");
}
if($this->CSStheme == '4'){
Requirements::css("mysite/css/pinklayout.css"); Requirements::css("mysite/css/pinktypography.css");
}
if($this->CSStheme == '5'){
Requirements::css("mysite/css/orangelayout.css"); Requirements::css("mysite/css/orangetypography.css");
}
if($this->CSStheme == '6'){
Requirements::css("mysite/css/yellowlayout.css"); Requirements::css("mysite/css/yellowtypography.css");
}
if($this->CSStheme == '7'){
Requirements::css("mysite/css/blacklayout.css"); Requirements::css("mysite/css/blacktypography.css");
}
}
This part of the code I believe is supposed to differentiate the different radio button options by specifying which CSS to use depending on what button is selected.
Now is where I become a bit lost, so bear with me. I do not know how to call this function on my page.ss so that the correct CSS is used.
I have been trying things along the lines of <% require themedCSS(layout) %> just after the base_tag in the head, where i swap the themedCSS to CSStheme or css.
I also tried to include things like
<% if CSStheme(2) %>
$init
<% end_if %>
or
<% if CSStheme(Blue) %>
$init
<% end_if %>
I simply do not know how to call the function on the page.ss, so if anybody is willing to help me out with this I would be greatly appreciative. I really am not all that confident with php and functions, but I feel like I am so close, but cant quite seem to get there.
Thanks in advance people.