Drupal(6&7):以编程方式更改活动主题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Drupal(6&7):以编程方式更改活动主题相关的知识,希望对你有一定的参考价值。
**Important: this snipplet has moved to Github.**- [Programmatically change the active theme in Drupal 6](https://gist.github.com/1973197)
- [Programmatically change the active theme in Drupal 7](https://gist.github.com/1973201)
// DRUPAL 6 function mymodule_init(){ global $custom_theme; $custom_theme = 'garland'; } // DRUPAL 7 /** * Defines a theme callback function per registered path. */ function mymodule_menu_alter(&$items) { $items['node/%node']['theme callback'] = 'mymodule_default_node_theme'; $items['node/%node/edit']['theme callback'] = 'mymodule_edit_node_theme'; } /** * Theme name callback: without parameters. */ function mymodule_default_node_theme() { return 'garland'; } /** * Theme name callback: with parameters. */ function mymodule_edit_node_theme($node) { return $node->type == 'page' ? 'seven' : mymodule_default_node_theme(); } /** * Use hook_custom_theme() if the choice of theme doesn't depend on the path. */ function mymodule_custom_theme() { //Example: Changes the theme name depending if the user has a special role or not. global $user; return 'bartik'; } }
以上是关于Drupal(6&7):以编程方式更改活动主题的主要内容,如果未能解决你的问题,请参考以下文章