Drupal: Rendering Fields

ComputerMinds zeigt zwei Wege Fields zu rendern, ohne dass man sich um die Sprache und Sanitisation Sorgen machen muss.

$output = field_view_field('node', $node, 'field_name');
That will return the sanitised, rendered field in its entirety, in the current language and in render-array form, so you’ll get all the associated markup.

Wer mehr Kontrolle will nutzt field_get_item und field_view_value

$node = node_load($nid);
$image = field_get_items('node', $node, 'field_image');
$output = field_view_value('node', $node, 'field_image', $image[0], array(
  'type' => 'image',
  'settings' => array(
    'image_style' => 'thumbnail',
    'image_link' => 'content',
  ),
));
 

bvt