Jump to:

3434 Posts in 1026 Topics by 866 members

Template Questions

SilverStripe Forums » Template Questions » multiple themes on one site

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

Page: 1 2
Go to End
Author Topic: 5858 Views
  • pinkdigital
    Avatar
    Community Member
    7 Posts

    multiple themes on one site Link to this post

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

  • effectwebdesign
    Avatar
    Community Member
    16 Posts

    Re: multiple themes on one site Link to this post

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

    ?>

  • effectwebdesign
    Avatar
    Community Member
    16 Posts

    Re: multiple themes on one site Link to this post

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

    ?>

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: multiple themes on one site Link to this post

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

    }

  • Hamish
    Avatar
    Community Member
    712 Posts

    Re: multiple themes on one site Link to this post

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

  • mccarville
    Avatar
    Community Member
    32 Posts

    Re: multiple themes on one site Link to this post

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

  • mccarville
    Avatar
    Community Member
    32 Posts

    Re: multiple themes on one site Link to this post

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

    }
       
    }

    ?>

  • Marlie511
    Avatar
    Community Member
    36 Posts

    Re: multiple themes on one site Link to this post

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

    5858 Views
Page: 1 2
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.