I am tring to load a full profile2.

I a trying the following code

$uid = user_load($node->uid);
$profile2_p = profile2_load_by_user($uid, 'profile2_profile');
print render($profile2_p);

I get an error saying object can't be used as array.

If I print_r $profile2_p then I get an array relating to the correct profile2 entity. How can I render this entity?


1 Answer 1


Looks like you can get a renderable array using profile2_view():

 * View a profile.
 * @see Profile::view()
function profile2_view($profile, $view_mode = 'full', $langcode = NULL, $page = NULL) {
  return $profile->view($view_mode, $langcode, $page);


See also that modules hook_user_view() which does the same:


 * Implements hook_user_view().
function profile2_user_view($account, $view_mode, $langcode) {
  foreach (profile2_get_types() as $type => $profile_type) {
    if ($profile_type->userView && $profile = profile2_load_by_user($account, $type)) {
      if (profile2_access('view', $profile)) {
        $account->content['profile_' . $type] = array(
          '#type' => 'user_profile_category',
          '#title' => $profile_type->getTranslation('label'),
          '#prefix' => '<a id="profile-' . $profile->type . '"></a>',
        $account->content['profile_' . $type]['view'] = $profile->view($view_mode);

With a single entity in your code, you can:


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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