1

I'm trying to make a custom view mode for user profiles. In my user-profile--myviewmode.tpl.php, I want to get the UID for the user whose profile it is.

The help text for user-profile.tpl.php states:

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

I used dpm() to print out the array $user_profile, but I couldn't find the UID anywhere.

Then I tried:

global $user;
$uid = $user->uid;

However, this doesn't work because when I use Views to render the view mode, it gives me the UID of the logged-in user, not the user whose profile is being rendered.

Is there a way to get the UID in user-profile.tpl.php? I need to get the UID to build some custom links based on it.

5

I found the uid under the elements >> #account object:

$elements['#account']->uid;

Good luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.