Sitefinity 4 以编程方式设置主题名称
在SiteFinity 4中,我们可以在用作页面模板的母版页的页面加载中设置主题名称吗?
最好的祝愿, 阿艺
In SiteFinity 4, Can we set Theme Name in Page Load of Master Page which is used as Page Template?
Best Wishes,
Aki
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
页面主题需要在asp.net中的Page_PreInit事件中设置,
不幸的是,母版页没有Page_PreInit事件,这就是您需要设置主题的地方。
这是母版页本身的限制,而不是 Sitefinity。
但是,可以通过创建自定义路由处理程序来拦截请求并动态修改主题,从而在运行时设置主题。
首先创建一个自定义路由类:
然后您需要在 Global.asax 文件中注册该路由:
现在每个请求都将通过该处理程序,您可以根据您需要的任何自定义条件修改主题。
我计划整理一篇博客文章和视频,更详细地介绍如何完成此操作以及可以用它做什么,但这是其工作原理的基本思想。
我希望这有帮助!
Page themes need to be set in the Page_PreInit event in asp.net
Unfortunately, Master Pages do not have the Page_PreInit event, and this is where you need to set the theme.
This is a limitation of master pages themselves, not Sitefinity.
However it is possible to set a theme at runtime by creating a custom route handler to intercept the request and modify the theme on the fly.
first create a custom route class:
Then you need to register that route in the Global.asax file:
Now each request will go through that handler, and you can modify the theme based on any custom condition you need.
I'm planning to put together a blog post and video that goes into more detail on how this is done and what you can do with it, but this is the basic idea of how it works.
I hope this is helpful!