print render(field_view_field('user', $user, 'field_avatar', array('settings' => array('image_style' => 'post_avatar'))));
Results in user object (from user_load) + field name and settings array.
You can also remove the label.
field_view_value is the same but with one element.
Example: displaying the first image in a field with multiple images:
$image = field_get_items('node', $node, 'field_image');
$output = field_view_value('node', $node, 'field_image', $image);
field_get_items is handy too. You don't have to look it up in the entire node object anymore, like:
But with field get items you don't have to woory about languages etc.
Example: hide label when field empty:
check with field_get_items if return is FALSE.
This is the company blog of
Drupal specialist Merge.nl.
We are located in Tilburg (Netherlands) and build websites using Drupal. More about us.
Content on this blog is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Netherlands License.