user-profile.tpl.php

You are here

  1. 7 modules/user/user-profile.tpl.php
  2. 6 modules/user/user-profile.tpl.php
  3. 8 core/modules/user/templates/user-profile.tpl.php

Default theme implementation to present all user profile data.

This template is used when viewing a registered member's profile page, e.g., example.com/user/123. 123 being the users ID.

Use render($user_profile) to print all profile items, or print a subset such as render($user_profile['user_picture']). Always call render($user_profile) at the end in order to print all remaining items. If the item is a category, it will contain all its profile items. By default, $user_profile['summary'] is provided, which contains data on the user's history. Other data can be included by modules. $user_profile['user_picture'] is available for showing the account picture.

Available variables:

  • $user_profile: An array of profile items. Use render() to print them.
  • Field variables: for each field instance attached to the user a corresponding variable is defined; e.g., $account->field_example has a variable $field_example defined. When needing to access a field's raw values, developers/themers are strongly encouraged to use these variables. Otherwise they will have to explicitly specify the desired field language, e.g. $account->field_example['en'], thus overriding any language negotiation rule that was previously applied.

Where the html is handled for the group. Where the html is handled for each item in the group.

See also

user-profile-category.tpl.php

user-profile-item.tpl.php

template_preprocess_user_profile()

File

modules/user/user-profile.tpl.php
View source
  1. <?php
  2. /**
  3. * @file
  4. * Default theme implementation to present all user profile data.
  5. *
  6. * This template is used when viewing a registered member's profile page,
  7. * e.g., example.com/user/123. 123 being the users ID.
  8. *
  9. * Use render($user_profile) to print all profile items, or print a subset
  10. * such as render($user_profile['user_picture']). Always call
  11. * render($user_profile) at the end in order to print all remaining items. If
  12. * the item is a category, it will contain all its profile items. By default,
  13. * $user_profile['summary'] is provided, which contains data on the user's
  14. * history. Other data can be included by modules. $user_profile['user_picture']
  15. * is available for showing the account picture.
  16. *
  17. * Available variables:
  18. * - $user_profile: An array of profile items. Use render() to print them.
  19. * - Field variables: for each field instance attached to the user a
  20. * corresponding variable is defined; e.g., $account->field_example has a
  21. * variable $field_example defined. When needing to access a field's raw
  22. * values, developers/themers are strongly encouraged to use these
  23. * variables. Otherwise they will have to explicitly specify the desired
  24. * field language, e.g. $account->field_example['en'], thus overriding any
  25. * language negotiation rule that was previously applied.
  26. *
  27. * @see user-profile-category.tpl.php
  28. * Where the html is handled for the group.
  29. * @see user-profile-item.tpl.php
  30. * Where the html is handled for each item in the group.
  31. * @see template_preprocess_user_profile()
  32. *
  33. * @ingroup themeable
  34. */
  35. ?>
  36. <div class="profile"<?php print $attributes; ?>>
  37. <?php print render($user_profile); ?>
  38. </div>

Related topics

Comments

The reference to render($content['field_example']) is a bit confusing since that variable is not exposed in this template.

also, $user->field_example is misleading as these variables are specific to the currently logged in user's settings, which is a separate matter from user-profile.tpl.php

i believe the author of this doc is confused

Agreed, I added an issue to the documentation.

just simple use

<?php
print render($user_profile['field_age']);
?>

(where "field_age" is the field name)
in user-profile.tpl.php to print field name

While the information is rendering, so is the label for the field name. How should the call be written to include the raw data but not the field label?

$user_profile is a renderable array, so all of the fields should come through unrendered. The title would typically be contained in an array element '#title'. This can be changed, unset, or set to NULL in the preprocess function 'themename_preprocess_user_profile', and this will stop the display of that title.

To take an example from the standard user profile - the annoying 'member for' display. This is stored in:

$user_profile['summary']['member_for']

This element has three properties - #type, #title, and #markup. We could set the title to NULL in the preprocess function as follows:

$user_profile['summary']['member_for']['#title'] = NULL

To completely remove the field we could use the hide function as follows:

hide($user_profile['summary']['member_for']);

or hide the summary altogether:

hide($user_profile['summary']);

There is more about renderable arrays at http://drupal.org/node/930760

I'm trying to use render($user_profile); but I'm getting the following error:

Fatal error: Call to undefined function render() in /home/sitename/public_html/sites/all/themes/theme_name/user-profile.tpl.php on line 6

I'm able to print the $user_profile however:

print $user_profile;

I'm trying to access just the user profile summary, but that's not working. Any idea why Drupal thinks render() is an undefined function when I try to use it in my user-profile.tpl.php?

Thanks.

Use 'print render($user_profile);'

$name = $user_profile['field_firstname'][0]['#markup'] => return custom field firstname but to return name or email of user???

$account = menu_get_object('user');
$mail = $account->mail;
$name = $account->name;

I noticed that using the simple $field_example as recommended works well, until I decided to change the display settings for those fields to hidden.

At that point, all $field_example became undefined, and I had to switch to accessing them via $elements['#account']->field_example['und'][0]['value']

Thank you! That was a tricky, trick! Really glad you figured it out.

If I have 3 profile types and I want to set a unique set of keywords for each profile type, how would this look in php? I need an if statement to identify the profile type then a statement to set the keywords to some (token) content in the database relevant to this profile.

How can we change format of the duration shown in user profile page

The structure of $user['summary']['member_for'] is:

<?php
$user_profile
['summary']['member_for'] = array(
   
'#type' => 'user_profile_item',
   
'#title' => t('Member for'),
   
'#markup' => format_interval(REQUEST_TIME - $account->created),
  );
?>

So you can modify $user['summary']['member_for']['#markup'] to get the format you want.

<b>Hire Date</b>: <?php print date("F jS, Y", mktime(0,0,0,$account->profile_hiredate["month"],$account->profile_hiredate["day"],$account->profile_hiredate["year"])); ?>
</strong><br />
<b>Birthday:</b> <?php print date("F jS", mktime(0,0,0,$account->profile_birthday["month"],$account->profile_birthday["day"])); ?><br>
<br />
</font>
<?php

Hire Date:

<?php
print date("F jS, Y", mktime(0,0,0,$account->profile_hiredate["month"],$account->profile_hiredate["day"],$account->profile_hiredate["year"]));
?>


Birthday:

<?php
print date("F jS", mktime(0,0,0,$account->profile_birthday["month"],$account->profile_birthday["day"]));
?>



<?php

can anyone help me here?

i cant get this to work, basically im trying to print 2 things on the user-profile.tpl.php

1. The date and time the user joined the site, prefably in this format: Day-Month-Year-Hour-Minutes-Seconds (example: 08122013165502)

2. Print todays date and time in the format above.

Thats it, any ideas? the suggestions above fail on D7

function yourtheme_theme($existing, $type, $theme, $path) {
$items = array();

$items['user_profile_form'] = array(
'render element' => 'form',
'path' => drupal_get_path('theme', 'yourtheme') . '/templates',
'template' => 'user-profile'
);

return $items;
}