- 7 modules/user/user-profile.tpl.php
- 6 modules/user/user-profile.tpl.php
- 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
template_preprocess_user_profile()
File
modules/user/user-profile.tpl.php- <?php
-
- /**
- * @file
- * 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.
- *
- * @see user-profile-category.tpl.php
- * Where the html is handled for the group.
- * @see user-profile-item.tpl.php
- * Where the html is handled for each item in the group.
- * @see template_preprocess_user_profile()
- *
- * @ingroup themeable
- */
- ?>
- <div class="profile"<?php print $attributes; ?>>
- <?php print render($user_profile); ?>
- </div>
-
Comments
render($content['field_example'])
PermalinkThe reference to render($content['field_example']) is a bit confusing since that variable is not exposed in this template.
also, $user->field_example is
Permalinkalso, $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
PermalinkAgreed, I added an issue to the documentation.
use <?php print render($user_profile['field_age']); ?>
Permalinkjust simple use
<?phpprint render($user_profile['field_age']);
?>
(where "field_age" is the field name)
in user-profile.tpl.php to print field name
Field Names
PermalinkWhile 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
Permalink$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'] = NULLTo 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
Render() not working?
PermalinkI'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 6I'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.
how to get e-mail address of user ?
Permalink$name = $user_profile['field_firstname'][0]['#markup'] => return custom field firstname but to return name or email of user???
menu_get_object('user')
Permalink$account = menu_get_object('user');
$mail = $account->mail;
$name = $account->name;
Accessing fields which are hidden in field display settings
PermalinkI noticed that using the simple
$field_exampleas recommended works well, until I decided to change the display settings for those fields to hidden.At that point, all
$field_examplebecame undefined, and I had to switch to accessing them via$elements['#account']->field_example['und'][0]['value']How do you set a meta tag for a specific profile type in code?
PermalinkIf 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.
"Member For -- Duration"
PermalinkHow can we change format of the duration shown in user profile page
Format duration
PermalinkThe 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.I need help Converting Snippet from D6 to D&
Permalink<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:<?phpprint date("F
PermalinkHire Date:
<?phpprint date("F jS, Y", mktime(0,0,0,$account->profile_hiredate["month"],$account->profile_hiredate["day"],$account->profile_hiredate["year"]));
?>
Birthday:
<?phpprint date("F jS", mktime(0,0,0,$account->profile_birthday["month"],$account->profile_birthday["day"]));
?>
<?php