gpt4 book ai didi

silverstripe - 我可以动态更改 SilverStripe 主题吗?

转载 作者:行者123 更新时间:2023-12-04 05:09:34 24 4
gpt4 key购买 nike

我为我的网站为 cecutients(视力低下的人)制作了附加主题。我可以按主页上的某个按钮动态更改站点主题吗?

最佳答案

是的,你可以这样做。我建议您在 Controller 上执行一个操作来更新主题。然后,您可以将当前事件的主题存储在 session 中,并在访问页面时使用它。

这是我如何实现的(在您的 Page_Controller 中):

class Page_Controller extends ContentController 
{
private static $allowed_actions = ['changeTheme'];

public function init(){
parent::init();

if ($theme = Session::get('theme')) {
Config::inst()->update('SSViewer', 'theme', $theme);
}
}

public function changeTheme()
{
$theme = $this->request->param('ID');
$existingThemes = SiteConfig::current_site_config()->getAvailableThemes();

if (in_array($theme, $existingThemes)) {
// Set the theme in the config
Config::inst()->update('SSViewer', 'theme', $theme);
// Persist the theme to the session
Session::set('theme', $theme);
}

// redirect back to where we came from
return $this->redirectBack();
}
}

现在你有一个 changeTheme在您的 Page_Controller 中采取行动,这意味着您可以在每个页面上使用它。然后您可以简单地通过链接触发主题更改,例如:
<%-- replace otherTheme with the folder-name of your theme --%>
<a href="$Link('changeTheme')/otherTheme">Change to other theme</a>

Page.ss在您的基本主题模板中,您可以为 cecutients 添加指向主题的链接。在 cecutients 的主题中,您添加一个指向 base-theme 的链接。

关于silverstripe - 我可以动态更改 SilverStripe 主题吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45115751/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com