Hi,

I have a template for the userprofiles. Each field is outputted by:
render($user_profile['field_myownfield'])

How can I output the user's email? I was told that I should use "$user->mail", but that gives me the email address from the user who is viewing the profile.

Thanks

Comments

This did the job:

<?php
$usr
= user_load(arg(1));
print
$usr->mail;
?>

Hi,

Can you paste the whole user-profile.tpl.php page. I am trying to do the same on drupal 7 website.

Thank You,

Ashish

-------------------
Ours is a world of nuclear giants and ethical infants. We know more about war than we know about peace, more about killing than we know about living.

Omar N. Bradley

Just use:

City:

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

Your field:
<?php
print render($user_profile['field_yourfield'])
?>

etc.

Create your own html and insert the "print render($user_profile['field_yourfield'])" :)

Hi,

sorry I'm a newbie (to theming and also to Drupal). How do I exactly do this? I added a file called user-profile.tpl.php in the templates folder of the theme I'm working with and put one such php statement in, as you suggest. But the user profile looks exactly as it did before. Do I need to activate the template somewhere?

Thanks a lot,
Lukas

If you look at the comments at the beggining of the file it says that :

* 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.
*

So if you print_r $user_profile in you template file it will give you the variables for the user you are currently looking..
Or even better

<?php
 
print '<pre>'. check_plain(print_r($user_profile)) .'</pre>';
?>

Hi,

Using user_load(arg(1)) is a bad idea, I used a preprocess function which we need to the active theme's template.php to achieve this :

<?php
/**
* Process variables for user-profile.tpl.php.
*
* The $variables array contains the following arguments:
* - $account
*
* @see user-profile.tpl.php
*/
function YOUR_THEMENAME_preprocess_user_profile(&$variables) {
 
$account = $variables['elements']['#account'];
 
// Helpful $user_profile variable for templates.
 
foreach (element_children($variables['elements']) as $key) {
   
$variables['user_profile'][$key] = $variables['elements'][$key];
  }
 
//Add mail to $user_profile variable
 
$variables['user_profile']['mail'] = $account->mail;
 
// Preprocess fields.
 
field_attach_preprocess('user', $account, $variables['elements'], $variables);
}
?>

Then in your user-profile.tpl.php, use $user_profile['mail'] to show email address.

Regards
Sagar
?>

Need help ?
Reach me on skype : sag_13684

Share your Posts, Url, Sites
www.sociopost.com

Works like a charm!

Just add a code field, and insert [user:mail] in the 'Field code' field. You can find other tokens below this field.

Please could you clarify what you mean by "code field" in this context? Thanks

Sure, there is some more information here: Add custom fields to a display.