On this page
Theming with Profile2
User-profile.tpl.php
If you are designing a custom template for your user profile pages and are using the Profile2 module, you probably are looking to add your custom fields to the user-profile.tpl.php template. Here is how this can be accomplished.
This assumes that you have a Profile2 profile type called my-profile. You may easily load your fields into your custom user-profile.tpl.php by printing them like this:
<?php print render($user_profile['profile_my-profile']['view']['profile2'][1]['field_example']); ?>
Where field_example is the machine name of your field. This example is setup for most fields such as text fields. Image fields can be rendered differently.
Node.tpl.php
To add the fields to the node.tpl.php template, we must first call the profile2 object like so:
<?php
$uid = user_load($node->uid);
$myprofile = profile2_load_by_user($uid, 'my-profile');
?>
Then we can print fields like this:
<?php if (isset($myprofile->field_example['und'][0]['value'])): ?>
<?php print ($myprofile->field_example['und'][0]['value']); ?>
<?php endif; ?>
As always you can view all printable items via the print_r function.
Help improve this page
You can:
- Log in, click Edit, and edit this page
- Log in, click Discuss, update the Page status value, and suggest an improvement
- Log in and create a Documentation issue with your suggestion