Hello,

I was wondering if anyone knows if it is possible to add the content profile field (ie first name) to the $user object so that it can be printed anywhere such as on page.tpl.php

I would appreciate the support!

Thank you

Comments

jeffschuler’s picture

You can use theme preprocess functions to make data accessible to your theme templates.

A couple good starting places are:

mttjn’s picture

i would like to know how to add content profile fields to $user object too...

anyone?

@jeffschuler: can you explain, please?

Thanks in advance!

Lehtóri’s picture

something like this should work:


global $user; 
$node_profile = content_profile_load(profile, $user->uid);
print $node_profile->field_firstname[0]["value"];

KingMoore’s picture

Try this:

/**
 * implementation of hook_init()
 * 
 * knows how to add profile node data to $user object
 */
function mymodule_init() {
  global $user;
  $user->profile = content_profile_load('profile', $user->uid);
}