What is the correct way to render a Drupal 7 image field and show the default image if the field is empty?
If I use
field_get_items it will simply return
FALSE when the field is empty.
Drupal Answers is a question and answer site for Drupal developers and administrators. It only takes a minute to sign up.Sign up to join this community
I think best practice would probably be to use
$view = field_view_field('node', $node, 'field_image'); print render($view);
That will render the field as if it was attached to an entity view, and as such will provide the default image if none is available.