I have set up a basic profile using drupal core. Then I have separate profile2 types for different types of users, with fields that only pertain to each type of user.

I'd like to include the profile2 fields (or the entire profile2 profile) on the core user page - user-profile.tpl.php.

How do I do this? I am not using render($user_profile) to print out the entire core profile page -- I call each field separately.

Comments

a.siebel’s picture

subscribe

mmilano’s picture

Not sure if this is the proper way to do it, but this worked for me.

// load profile fields
$profile = profile2_load_by_user($elements['#account']);

// then access fields like this
print $profile['main']->field_gender['und'][0]['value'];
fago’s picture

Something like that should be done in the template preprocessor.

drupik’s picture

#2 how to setup this? Its not working for me.

chandan.drupalchamp’s picture

You can use like ...


$user_obj = user_load($row->uid);
$profile = profile2_load_by_user($user_obj);

//check your profile data....

print"<pre>";
print_r($profile);
print"</pre>";

gvanto’s picture

Hey sorry to sound dumb but where is this template preprocessor? Which file should I create?

I've created a page--front.tpl.php before, for example to override the front page's template output file - what is the appropriate file to create for a profile2 profile?

Many thanks
gvanto
profile2 newbie

Dropper’s picture

Look on the page api.drupal.org - search for template_preprocess functions. There are preprocess functions for various templates. This is basic Drupal knowledge you should get to know.

faqing’s picture

mmilano, Thank you so much. #2 is working for me!

faqing’s picture

Status: Active » Closed (fixed)

we can close this. I think.

faqing’s picture

Status: Closed (fixed) » Needs work

It only works for 'TEXT" display, it does not support for References, List display.

faqing’s picture

Status: Needs work » Closed (fixed)

For node reference and taxonomy term reference, the easiest way:

<?php
global $user;
$uid = user_load($user->uid);
$profile_myprofile=profile2_load_by_user($uid, 'myprofile');
?>
print drupal_render(field_view_field('profile2', $profile_myprofile, 'field_photo', 'value'));

Further info, see here:
http://thanhsiang.org/faqing/node/178

nbchip’s picture

Status: Closed (fixed) » Needs work

I dont see answer on how to print and render entire profile2 profile in for example user-profile.tpl.php

After loading particular user profile

$user_uid = $elements['#account']->uid;
$profile = profile2_load_by_user($user_uid, 'athlete');

Is there a way to render Entire / Complete profile with all fields, at once, and not field by field.

thx.

infines’s picture

Priority: Normal » Major

#2 works, but I am getting errors for the fields I am pulling...

Notice: Undefined index: portfolio in include() (line 5 of /home/folioh/public_html/sites/all/themes/folioh3/templates/user-profile.tpl.php).
Notice: Trying to get property of non-object in include() (line 5 of /home/folioh/public_html/sites/all/themes/folioh3/templates/user-profile.tpl.php).

Solution?

infines’s picture

This is what I'm using. Works like a charm. Note: "portfolio" is the name of my profile type.

 global $user;
$uid = user_load($user->uid);
$portfolio = profile2_load_by_user($uid, 'portfolio');

print render($portfolio->field_title['und'][0]['value']);

infines’s picture

Title: Profile2 fields in user-profile.tpl.php » Profile2 fields in user-profile.tpl.php Add docs
Category: support » task

I'm changing this to be a task to add to the docs.

infines’s picture

Assigned: Unassigned » infines
infines’s picture

Status: Needs work » Needs review
infines’s picture

Status: Needs review » Closed (fixed)
deggertsen’s picture