<p>You may want to try this:</p>

<pre><code>{% for image in entry.illustration %}
  {% if image %}
      &lt;a href="{{ entry.url }}" class="flag__img"&gt;&lt;img src="{{ image.getUrl() }}" alt="{{ entry.altText }}" class="profile__image" /&gt;&lt;/a&gt;
  {% else %}
    &lt;p&gt;No image.&lt;/p&gt;
  {% endif %}
{% endfor %}  
</code></pre>

<p>(Assuming the altText field is an entry field.) :)</p>

CC BY-SA 3.0
2014-07-14T15:07:36.027Z
2014-07-14T15:07:36.027Z
Angela
<p>If you want to make it a little smaller, you could use a ternary statement, so on your img tag, you could use the following</p>

<pre><code>&lt;img src="{{ image ? image.getUrl : 'http://example.com/image.png' }}" /&gt;
</code></pre>

<p>So you're full snippet would be </p>

<pre><code>{% for image in entry.illustration %}
        &lt;a href="{{ entry.url }}" class="flag__img"&gt;
            &lt;img src="{{ image ? image.getUrl : 'http://example.com/image.png' }}" alt="{{ image.altText ? image.altText : "Default Alt Text" }}" class="profile__image" /&gt;

        &lt;/a&gt;
{% endfor %}
</code></pre>

<p>A ternary statement is basically a shorthand if statement.</p>

<pre><code>{{ (condition is true) ? do this : else do this }}
</code></pre>

<p>Also changed <code>entry.altText</code> to <code>image.altText</code> in the for loop. That may be where you are going wrong?</p>

CC BY-SA 3.0
2014-07-14T13:48:02.447Z
Thanks. Could you be a bit more specific please? This didn't do much good.
osh
CC BY-SA 3.0
2014-07-14T14:51:42.377Z
edited the above to help you out.
Seán O'Grady
CC BY-SA 3.0
2014-07-14T15:32:06.680Z
Thanks for helping out. I now have this, but it still doesn't output the placehold.it image: {% for image in employee.illustration %}
        <a href="{{ employee.url }}" class="flag__img">
            <img src="{{ image ? image.getUrl : 'http://placehold.it/60x30' }}" alt="{{ image.altText ? image.altText : "Default Alt Text" }}" class="profile__circular" />
        </a>
{% endfor %}
osh
CC BY-SA 3.0
2014-07-14T15:42:37.930Z
try http:// before it ?
Seán O'Grady
CC BY-SA 3.0
2014-07-14T15:58:01.340Z
It actually has http:// before it, just not when I paste the code in here :)
osh
CC BY-SA 3.0
2014-07-14T12:06:22.660Z
2014-07-14T14:51:24.580Z
2014-07-14T14:51:24.580Z
Seán O'Grady
<p>I am assuming that <em>illustration</em> is an asset field, and you want to display all the images, or <em>No image</em> if there are none. You can do that with an <code>else</code> clause on the <code>for</code>.</p>

<pre><code>{% for image in entry.illustration %}
  &lt;a href="{{ entry.url }}" class="flag__img"&gt;
    &lt;img src="{{ image.getUrl }}" alt="{{ entry.altText }}" class="profile__image"&gt;
  &lt;/a&gt;
{% else %}
  &lt;p&gt;No image.&lt;/p&gt;        
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-07-14T18:02:15.873Z
2014-07-14T18:02:15.873Z
Marion Newlevant
<p>I'm trying to do this:</p>

<pre><code>{% for image in entry.illustration %}
    {% if image | length %}
        &lt;a href="{{ entry.url }}" class="flag__img"&gt;
            &lt;img src="{{ image.getUrl }}" alt="{{ entry.altText }}" class="profile__image"&gt;
        &lt;/a&gt;
    {% else %}  
        &lt;p&gt;No image.&lt;/p&gt;        
    {% endif %}
{% endfor %}
</code></pre>

<p>Without any luck. What would be a good way of telling craft to do something else if entry.illustration does not have an image defined?</p>

<templating>
Showing a generic image when no image is chosen
# Showing a generic image when no image is chosen

(Asked by: username_0 on 2014-07-14)

I'm trying to do this:
{% for image in entry.illustration %}
    {% if image | length %}
        
            
        
    {% else %}  
        No image.        
    {% endif %}
{% endfor %}

Without any luck. What would be a good way of telling craft to do something else if entry.illustration does not have an image defined?

**Tags:** templating

---

## 3 answers

### Answer by username_1 on 2014-07-14. Score: 3

You may want to try this:
{% for image in entry.illustration %}
  {% if image %}
      
  {% else %}
    No image.
  {% endif %}
{% endfor %}  

(Assuming the altText field is an entry field.) :)


---

### Answer by username_2 on 2014-07-14. Score: 2

If you want to make it a little smaller, you could use a ternary statement, so on your img tag, you could use the following


So you're full snippet would be 
{% for image in entry.illustration %}
        
            

        
{% endfor %}

A ternary statement is basically a shorthand if statement.
{{ (condition is true) ? do this : else do this }}

Also changed entry.altText to image.altText in the for loop. That may be where you are going wrong?

> **Comments:**
> **username_0**: Thanks. Could you be a bit more specific please? This didn't do much good.  
> **username_2**: edited the above to help you out.  
> **username_0**: Thanks for helping out. I now have this, but it still doesn't output the placehold.it image: {% for image in employee.illustration %}         <a href="{{ employee.url }}" class="flag__img">             <img src="{{ image ? image.getUrl : 'http://placehold.it/60x30' }}" alt="{{ image.altText ? image.altText : "Default Alt Text" }}" class="profile__circular" />         </a> {% endfor %}  
> **username_2**: try http:// before it ?  
> **username_0**: It actually has http:// before it, just not when I paste the code in here :)  

---

### Answer by username_3 on 2014-07-14. Score: 1

I am assuming that illustration is an asset field, and you want to display all the images, or No image if there are none. You can do that with an else clause on the for.
{% for image in entry.illustration %}
  
    
  
{% else %}
  No image.        
{% endfor %}


---

