以编程方式应用主题
我想为每个用户角色应用单独的主题。我知道可以选择从管理端执行此操作,但我想以编程方式执行此操作。
我找到了一个使用全局 $custom_theme 的选项。我将代码更改为
function mymodule_config_preprocess_page(&$variables) {
global $custom_theme;
$custom_theme = 'bluemarine';
init_theme();
}
但它不影响主题。这需要任何修改吗?
请帮助我
I want to apply a separate theme for each user role. I know there is option to do this from the admin side, but I want to do this programmatically.
I found an option using global $custom_theme. I changed my code as
function mymodule_config_preprocess_page(&$variables) {
global $custom_theme;
$custom_theme = 'bluemarine';
init_theme();
}
But it is not affecting the theme .Is this required any modifications?
Pls help me
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为在预处理变量时更改主题为时已晚,您可能需要在
hook_init()
:据我所知,不需要调用
init_theme()
因为 Drupal 稍后会在此过程中为您执行此操作,使用全局$custom_theme
来决定使用哪个主题。I think it's too late to change the theme at the point of preprocessing variables, you'll probably want to do this in
hook_init()
:As far as I know there's no need to call
init_theme()
as Drupal will do this for you later on in the process, using the global$custom_theme
to decide which theme to use.当执行
mymodule_config_preprocess_page()
时,主题已经初始化。一旦初始化,主题就无法重新初始化。查看 ThemeKey 模块代码,它更改了
$custom_theme
中的值代码>hook_init()。这可能是在 Drupal 6 中实现主题更改的最佳钩子。The theme is already initialized when your
mymodule_config_preprocess_page()
is executed. once initialized, the theme cannot be re-initialized.Looking at the ThemeKey module code, it changes the value of
$custom_theme
inhook_init()
. That's probably the best hook to implement theme change in Drupal 6.