I have made for my site additional theme for cecutients (people with low eyesight). Can I dynamically change site theme pushing some button on the main page?
I have made for my site additional theme for cecutients (people with low eyesight). Can I dynamically change site theme pushing some button on the main page?
An update for Silverstripe 4.x version:
use SilverStripe\CMS\Controllers\ContentController;
use SilverStripe\Control\Session;
use SilverStripe\SiteConfig\SiteConfig;
use SilverStripe\View\SSViewer;
use SilverStripe\Core\Config\Config;
class PageController extends ContentController
{
private static $allowed_actions = ['changeTheme'];
protected function init()
{
parent::init();
if ($theme = $this->getRequest()->getSession()->get('theme')) {
SSViewer::config()->update('theme_enabled', true);
SSViewer::set_themes([$theme]);
}
}
public function changeTheme()
{
$theme = $this->request->param('ID');
$existingThemes = Config::inst()->get('SilverStripe\View\SSViewer', 'themes');
if (in_array($theme, $existingThemes)) {
SSViewer::config()->update('theme_enabled', true);
SSViewer::set_themes([$theme]);
$this->getRequest()->getSession()->set('theme', $theme);
}
return $this->redirectBack();
}
}