I'd like to be able to control which fields in a user's profile are displayed, depending on the role of the logged in user.

I've set up a custom user_profile.tpl.php file, and it seems to me that I should be able to control what's displayed using a simple if statement based on the logged in user's role.

The problem is I can't work out how to get the role of the logged in user without using the global $user variable (because of course as soon as I add that to the page the profile gets replaced with the logged in user's profile).

Is there another way to do this?

Thanks

Barry

Comments

Tistur’s picture

I used the global variable:

<?php

 $view_user = $user;
  global $user;

?>

And then, checked the $user:

  <?php

 if (($user->uid == arg(1) || user_access('access private content', $user)) && ($view_user->profile_priv_general)): ?>

    <dl class="profile-private">
      <dt class="profile-profile_priv_general">Private Notes</dt>
      <dd class="profile-profile_priv_general"><?php print check_markup($view_user->profile_priv_general); ?></dd>  
    </dl>

  <?php endif; ?>


?>
Anonymous’s picture

Thanks very much for the response Tistur.

I think I understand it :) Will give it a try.

Rob T’s picture

I used something like this...

<?php
    global $user;
?>

<?php 
    if (in_array('authenticated user', $user->roles)) { print "hi"; } 
?>