I've been trying to get the following function to work in Drupal 7, where an unauthenticated user sees a different article template (in this case, node--article2.tpl) than a user that's logged in. I get no php errors, but the template doesn't change if I'm logged out. What am I doing wrong here?

   function mytheme_preprocess_node(&$variables) {
   $node = $variables['node'];

   if($node->type === 'article'){
   global $user;
   if($user->uid == 0){
   $variables['template_file'] = 'node__article2';

Additionally, I'd like the function to look at an article's published state as well. We're using the custom publishing options module that adds a publishing state of "archived."

So basically unauthenticated users will get a different template that has a publishing state of archived.

  • Is page caching enabled? If so, the page is cached in one of the two templates. – Bart Sep 4 '12 at 16:48
  • Turned if off and it's still not working. I'm guessing that it's not finding the template file for whatever reason. – Mike Morgera Sep 4 '12 at 18:15

change code

$variables['template_file'] = 'node__article2';


$variables['theme_hook_suggestions'][] = 'node__article2';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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