Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By therapyportal on
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
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
Error is from user_load
Check if it is working with only:
$user_profile = user_load(arg(1));
Don't pass an array. it works.
thank u so much that fixed it
i just replied to u but realised i replied on the wrong post lol sorry