0

I want to show the amount of credits the user has. I know the $user object has the following properties:

uid - name - pass - mail - theme - signature - signature_format - created - access - login - status - timezone - language - picture - init - data - sid - ssid - hostname - timestamp - cache - session - roles

But I have also extended user properties like address street, address city, user credits, ... . But how can I print those properties in my layout theme? They are also not in my users table in my database.

2 Answers 2

1

You can use the user_load() to load all additional fields.

E.g.

global $user;
$account = user_load($user->uid);
$street = $account->field_address_street[LANGUAGE_NONE][0]['value'];
1

First, to access the additional user fields you will need to load the full user object using an available user id with the user_load() function.

global $user; //This contains the basic information for your current user.  

$account = user_load($user->uid); //$account now includes all of your custom account fields.

Now that you have the fully loaded user object you will need to choose a template to modify.

Depending on where the values need to be, this could be one of many templates. I highly recommend checking out the Theme Developer module to help find preprocessing functions and available templates to override.

There is some fantastic information on setting up variables for use in a template here.

Example snip:

<?php
function drop_preprocess_foo(&$variables) {
  // Do not do this unless you mean to:
  $variables['foo_list'] = array('list item 4');
  // Instead do this:
  $variables['foo_list'][] = 'list item 4';
}
?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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