Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

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.

Template Questions /

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo, swaiba

multiple themes on one site


Go to End


13 Posts   9508 Views

Avatar
pinkdigital

Community Member, 7 Posts

11 January 2009 at 1:31am

Is it possible to use different themes for different sections of a website with silverstripe, ideally without having to use a query string.

Avatar
effectwebdesign

Community Member, 16 Posts

14 January 2009 at 3:02am

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;
}

}
}

?>

Avatar
effectwebdesign

Community Member, 16 Posts

14 January 2009 at 3:07am

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');

?>

Avatar
Willr

Forum Moderator, 5523 Posts

14 January 2009 at 10:05am

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");

  
 }

Avatar
Hamish

Community Member, 712 Posts

14 January 2009 at 10:31am

And don't forget that you could store the theme as a database field, giving you full theme configuration from the CMS.

Avatar
mccarville

Community Member, 32 Posts

16 January 2009 at 3:17pm

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...

Avatar
mccarville

Community Member, 32 Posts

17 January 2009 at 3:24am

Edited: 17/01/2009 3:32am

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");

}

}

?>

Avatar
Marlie511

Community Member, 36 Posts

22 July 2009 at 8:17am

Edited: 22/07/2009 9:15am

Thank you for your directions! I figured out how to switch themes!

Go to Top