How to add a profile field in page--user.tpl.php I need to put a profile field in page--user.tpl.php.

I try this :

function THEME_preprocess_page(&amp;$variables) {
  global $user;
  $user_fields = user_load($user-&gt;uid);
  $variables['myfield'] = '';
  $myfield = $user-&gt;field_myfield;
  if($myfield) {
    $variables['myfield'] = $myfield['und'][0]['safe_value'];
  }
}


But i have an error :

Notice : Undefined property: stdClass::$field_myfield dans THEME_preprocess_page()


Do you know where should come the problem ?
try using field_get_items()

$field_myfield = field_get_items('user', $user, 'field_myfield');
$myfield_value = field_view_value('user', $user, 'field_myfield', $field_myfield[0]);
$variables['myfield'] = render($myfield_value);


More info here and here