Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
By Mr_Zoidberg on
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 =
This did the job:
Hi, Can you paste the whole
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
Just use: City: <?phpprint
Just use:
City:
Your field:
etc.
Create your own html and insert the "print render($user_profile['field_yourfield'])" :)
for a newbie
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 thetemplates
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
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
Hi, Using user_load(arg(1))
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 :
Then in your user-profile.tpl.php, use $user_profile['mail'] to show email address.
Regards
Sagar
?>
Acquia certified Developer, Back end and Front specialist
Need help? Please use my contact form
Thanks!
Works like a charm!
Display suite is also an option
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
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.
Great idea!
Thanks for that. Works a treat.