Display Suite code field – how to use another image field conditionally In my content type I want to show the main image if the thumbnail field is empty. So I use the Display Suite code field and I enter the following code:

&lt;?php 
dsm($entity);
if(empty($entity-&gt;field_thumbnail)){
    print_r('Thumbnail missing');
    // What code to put here to enable or render another image field 
}
?&gt;


When the tumbnail is missing the above code works, but instead of text I want to display another image field, when the thumbnail is missing. I have tried everything I can think of, but the main image dose not show :-(.
It's because you have nothing in renderable format yet.

Look at function field_view_field


  Returns a renderable array for the value of a single field in an
  entity.


Then change your code like this:

&lt;?php 
dsm($entity);
if(empty($entity-&gt;field_thumbnail)){
    $renderable = field_view_field('node',$entity,'field_main_image',array('settings' =&gt; array('image_style' =&gt; 'thumbnail')));
    print drupal_render($renderable );
}
?&gt;


Note that this is not the only way to get html from field values. You can use theme functions and load that with values you find on $entity object and print that if you wish.