以编程方式应用主题

发布于 2024-12-14 15:05:02 字数 300 浏览 2 评论 0原文

我想为每个用户角色应用单独的主题。我知道可以选择从管理端执行此操作,但我想以编程方式执行此操作。
我找到了一个使用全局 $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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

本王不退位尔等都是臣 2024-12-21 15:05:02

我认为在预处理变量时更改主题为时已晚,您可能需要在 hook_init()

function mymodule_init() {
  global $custom_theme;   
  $custom_theme = 'bluemarine';
}

据我所知,不需要调用 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():

function mymodule_init() {
  global $custom_theme;   
  $custom_theme = 'bluemarine';
}

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.

海未深 2024-12-21 15:05:02

当执行 mymodule_config_preprocess_page() 时,主题已经初始化。一旦初始化,主题就无法重新初始化。

查看 ThemeKey 模块代码,它更改了 $custom_theme 中的值代码>hook_init()。这可能是在 Drupal 6 中实现主题更改的最佳钩子。

function mymodule_init() {
  global $custom_theme;   
  $custom_theme = 'bluemarine';
}

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 in hook_init(). That's probably the best hook to implement theme change in Drupal 6.

function mymodule_init() {
  global $custom_theme;   
  $custom_theme = 'bluemarine';
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文