3214 Posts in 848 Topics by 810 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1448 Views |
-
Adding variable .css files

24 February 2009 at 12:14pm
Hello
I am putting together a site with 3 different sections, ie. Sales & Marketing, Branding & Default. Each section needs the same layout, but different colors in the submenu and headings.
I found this post and put the following code into Controller.php:
function init(){
$cssFile = 'default.css';
switch($this->URLSegment){
case 'test': $cssFile = '1.css'; break;
case 'contact': $cssFile = '2.css'; break;
// etc.
}Requirements::css($cssFile);
}However, back on the site if I create a new page "test" (url=test, title=test, navigation=test) the 1.css file is definitely not called. What am I doing wrong?
Also, is it possible to use wildcards so that any page with "test" in its title/url, ie. "test-page1" or "test-ing" will call the 1.css file?
Many thanks in advance.
-
Re: Adding variable .css files

25 February 2009 at 7:50pm Last edited: 25 February 2009 7:50pm
To me, this seems like the wrong way of doing things - I think what you should really be doing is defining subclasses of Page, then requiring different CSS for each one. This will also give you the opportunity to add more changes to the different sections later on.
-
Re: Adding variable .css files

26 February 2009 at 6:30pm
Thanks. I had come to a similar conclusion.
I've used this method:
Create an Enum field on the page class:
static $db = array(
"PageStyle" => "Enum('Red,Green,Blue')",
);function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab("Root.Content.Main", new DropdownField("PageStyle", "Style", array(
"Red" => "Red",
"Green" => "Green"
"Blue" => "Blue",
)));
return $fields;
}Then in the template
<body class="style-$PageType">which was suggested in this earlier forum post.
| 1448 Views | ||
|
Page:
1
|
Go to Top |


