1

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

2 Answers 2

3

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.

3
  • i changed the condtion then the theme was applied but ut gives me a warning message " warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'phptemplate_menu_local_tasks' was given in" Nov 10, 2011 at 9:29
  • 1
    Navigate to this path : /admin/build/themes. Scroll to the bottom and click on 'Save Configuration', that should clear the cache and fix your problem.
    – Clive
    Nov 10, 2011 at 9:36
  • Am sorry to disturb u. One more issue is there. The theme is not affecting the block page ie. admin/build/block Nov 10, 2011 at 11:50
0

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';
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.