<p>You can use the <a href="http://twig.sensiolabs.org/doc/filters/length.html"><code>length</code></a> Twig filter for that.</p>

<pre><code>{% if entry.featureImage | length %}
    {% set image = entry.featureImage.first() %}
    &lt;div class="imagewrapper"&gt;
       &lt;img src="{{ image.getUrl() }}" width="{{ image.getWidth('banner') }}" height="{{ image.getHeight('banner') }}"&gt;
    &lt;/div&gt;
{% endif %}
</code></pre>

<p>If there isn't an image in <code>featureImage</code> then nothing will be output.</p>

CC BY-SA 3.0
2014-06-25T02:45:27.170Z
2014-06-25T02:45:27.170Z
Alex Kendrick
<p>I know how to add images into my template:</p>

<pre><code>{% set image = entry.featureImage.first() %}
&lt;div class="imagewrapper"&gt;
    &lt;img src="{{ image.getUrl() }}" width="{{ image.getWidth('banner') }}" height="{{ image.getHeight('banner') }}"&gt;
&lt;/div&gt;
</code></pre>

<p>But what if my client doesn't have feature images for all of his entries? I need some function that'll tell the website, if there is no image, omit <code>&lt;div class="imagewrapper"&gt;</code>.</p>

<p>Perhaps some kind of if/else statement that I can use:</p>

<pre><code>{% if
    //the featureimage for this entry is filled in
%}
    {% set image = entry.featureImage.first() %}
    &lt;div class="imagewrapper"&gt;
        &lt;img src="{{ image.getUrl() }}" width="{{ image.getWidth('banner') }}" height="{{ image.getHeight('banner') }}"&gt;
    &lt;/div&gt;
{% endif %}
</code></pre>

<templating><entries>
How do I use an if/else statement to determine if a field is filled in?
# How do I use an if/else statement to determine if a field is filled in?

(Asked by: username_0 on 2014-06-25)

I know how to add images into my template:
{% set image = entry.featureImage.first() %}

    


But what if my client doesn't have feature images for all of his entries? I need some function that'll tell the website, if there is no image, omit .
Perhaps some kind of if/else statement that I can use:
{% if
    //the featureimage for this entry is filled in
%}
    {% set image = entry.featureImage.first() %}
    
        
    
{% endif %}

**Tags:** templating, entries


---

## 1 answers

### Answer by username_1 on 2014-06-25. Score: 9 | Accepted answer

You can use the length Twig filter for that.
{% if entry.featureImage | length %}
    {% set image = entry.featureImage.first() %}
    
       
    
{% endif %}

If there isn't an image in featureImage then nothing will be output.


---

