2

Possible Duplicate:
How to print id of user whose profile I visit rather than id of logged in user?

I would like to print the id of the user on his profile page? How can I do it in Drupal 7. So far I could only print logged in user id..Any advice appreciated.

0

2 Answers 2

4

You can use hook_user_view(). I have small module named nova to customise various aspects of drupal. So if I use the following function in my module, I get the title "Id of the Member" and then the output of uid.

function nova_user_view($account) {
  $account->content['myid'] = array(
    '#type' => 'user_profile_item',
    '#title' => t('Id of the Member'),
    '#markup' => $account->uid,
  );
}

Please let me know if it works for you or if you need more explanation.

1
  • 2
    When building the profile page, Drupal calls all hook_user_view() implementations. Each one can add its own item to display on the profile page as element of the $account->content array. $account is actually the user object for the viewed profile. In most Drupal code, to avoid confusion, the convention is to use $user for the current currently logged-in user and $account for other any other user. Jun 20, 2011 at 10:26
5

If you add this to the user-profile.tpl.php template, it will show the UID of user account being viewed.

<?php echo $account->uid;?>

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