Hello all, I'm trying to print out specific profile fields depending on the profile users role using the code below in user-profile.tpl.php of our theme.

<?php
if (arg(0) == 'user'){
   
$user_profile = user_load(array('uid' => arg(1)));
    if (
in_array('Free', array_values($user_profile->roles))){
        echo
'<h1>Free profile</h1>';
       
//FREE PROFILE FIELDS HERE
   
}
    if (
in_array('Subscriber', array_values($user_profile->roles))){
        echo
'<h1>Subscriber profile</h1>';
       
//SUBSCRIBER PROFILE FIELDS HERE
   
print render($user_profile['field_headline']);
    }
}
else {
//
}
?>

However when printing the profile fields we get the error 'Fatal error: Cannot use object of type stdClass as array' I've only just begun coding with Drupal so not sure what I've done wrong! Thanks in advance...

Comments

im trying to achieve the exact same thing?

so far i have this, you can use it in your use-profile.tpl.php file. You need to get the role id, which is the number assigned to the roles

global $user;
if (array_key_exists('ROLE ID', $user->roles)) {
  print $front_page;
}
elseif (array_key_exists('SOME OTHER ROLE ID', $user->roles)) {
  print t('Home');
}
else {
  //don't show.
}

Check if it is working with only:

$user_profile = user_load(arg(1));

Don't pass an array. it works.

i just replied to u but realised i replied on the wrong post lol sorry