I am using PHPTemplate. I have seen code to change the theme for different node types using the phptemplate_variable function and defining a template.php file. I have also seen some snippets to access the user role and turn off and on content based on the role, but it doesnt seem to work when I try to do this in the template.php file. here is my code:

function _phptemplate_variables($hook, $vars = array()) {
global $user;
if (in_array('admin',$user->roles)) {
        $vars['template_file'] = 'admin';
} 
else if (in_array('employee',$user->roles)) {
        $vars['template_file'] = 'employee';
} 
  return $vars;
} 

Any help would be greatly appreciated.

Comments

hrasheed’s picture

after updating my code, now the problem is that i get "warning: array_merge()" and "warning: extract()" error messages. i added the lines to switch on hook, which i guess i had left out before:


function _phptemplate_variables($hook, $vars = array()) {
global $user;
  switch ($hook) {
    case 'page':
	if (in_array('admin',$user->roles)) {
		$vars['template_file'] = 'admin';
	}
	else if (in_array('employee',$user->roles)) {
		$vars['template_file'] = 'employee';		
	}
   return $vars;
  }


}

Rosamunda’s picture

I didn´t get how to apply it to the general common themes...
$vars['template_file'] = 'employee';
Should the word "employee" be replaced by the theme name?

Thanks in advance!

Rosamunda
Buenos Aires | Argentina
www.ligadelconsorcista.org