Is it possible to use different themes for different sections of a website with silverstripe, ideally without having to use a query string.
This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.
Please use forum.silverstripe.org for any new questions
(announcement).
The forum archive will stick around, but will be read only.
You can also use our Slack channel
or StackOverflow to ask for help.
Check out our community overview for more options to contribute.
Is it possible to use different themes for different sections of a website with silverstripe, ideally without having to use a query string.
Yes it is possible but I'm struggling with that too. In DotNetNuke you can apply different page templates and container templates right from the CMS so this seems very tedious to me as a designer.
There is a post: http://silverstripe.org/archive/show/218016 that got me close.
I can see how changing placing <body id="$URLSegment"> in the Page.ss file and modifying your CSS would work, but that would be very tedious style work.
I've tried this other solution at the bottom of that post, but I can't get it to work. Can anyone help us?
switch($this->URLSegment) {
case 'home' :
SSViewer::set_theme('theme1');
break;
case 'otherpage':
SSViewer::set_theme('theme2');
break;
}
Below you can see it in my actual code. I'm not a programmer so when the post said "put it in your init" function maybe I have it in the wrong spot? The testimonials page is trying to call the dreamy template, but it is broken, trying to import styles from blackcandy. I have verified the dreamy template install is fine. Please help. Thanks!
<?php
class Page extends SiteTree {
static $db = array(
);
static $has_one = array(
);
}
class Page_Controller extends ContentController {
function init() {
parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
switch($this->URLSegment) {
case 'home' :
SSViewer::set_theme('blackcandy');
break;
case 'testimonials':
SSViewer::set_theme('dreamy');
break;
}
}
}
?>
PS: Here is my _config.php file. I think my problem might have to do with this file calling blackcandy, but it seems I have to specify some theme here or the page is blank.
<?php
global $project;
$project = 'mysite';
global $databaseConfig;
$databaseConfig = array(
"type" => "MySQLDatabase",
"server" => "localhost",
"username" => "construc_user",
"password" => "Construct777",
"database" => "construc_db",
);
// Sites running on the following servers will be
// run in development mode. See
// http://doc.silverstripe.com/doku.php?id=devmode
// for a description of what dev mode does.
Director::set_dev_servers(array(
'localhost',
'127.0.0.1',
));
// This line set's the current theme. More themes can be
// downloaded from http://www.silverstripe.com/cms-themes-and-skin
SSViewer::set_theme('blackcandy');
?>
Looks like you are on the right track. Maybe try move your switch statement above the parent::init() in that same function
Like this
function init() {
switch($this->URLSegment) {
case 'home' :
SSViewer::set_theme('blackcandy');
break;
case 'testimonials':
SSViewer::set_theme('dreamy');
break;
}
parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
And don't forget that you could store the theme as a database field, giving you full theme configuration from the CMS.
How would you store it as a database field and add it to the CMS? It would be amazing! if I could add the functionality... let user choose a theme... I would get cheers!
In the code above " case 'home' : " Does that mean that it will only effect the page name home? Is there a way to also apply that to the children of the named page?... Alothough it seems a mute point if I can get CMS theme selection working...
This is the code I have come up with so far... as now I getting a parse error on line "SSViewer::set_theme('$Theme');"
---------------------------
<?php
class Page extends SiteTree {
static $db = array(
'Theme' => "Enum('higherground,blackcandy','higherground')"
);
static $has_one = array(
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new DropdownField(
'Theme',
'Select A Theme:',
singleton('Page')->dbObject('Theme')->enumValues()
));
return $fields;}
}
class Page_Controller extends ContentController {
function init() {
switch($this->URLSegment) {
SSViewer::set_theme('$Theme');
break;
}
parent::init();
Requirements::themedCSS("layout");
Requirements::themedCSS("typography");
Requirements::themedCSS("form");
}
}
?>
Thank you for your directions! I figured out how to switch themes!