Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T15:07:36.027Z
Answers.LastActivityDate: 2014-07-14T15:07:36.027Z
Answers.UserDisplayName: Angela
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T13:48:02.447Z
Answers.Text: Thanks. Could you be a bit more specific please? This didn't do much good.
Answers.UserDisplayName: osh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T14:51:42.377Z
Answers.Text: edited the above to help you out.
Answers.UserDisplayName: Seán O'Grady
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T15:32:06.680Z
Answers.Text: 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 %}
Answers.UserDisplayName: osh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T15:42:37.930Z
Answers.Text: try http:// before it ?
Answers.UserDisplayName: Seán O'Grady
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T15:58:01.340Z
Answers.Text: It actually has http:// before it, just not when I paste the code in here :)
Answers.UserDisplayName: osh
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T12:06:22.660Z
Answers.LastActivityDate: 2014-07-14T14:51:24.580Z
Answers.LastEditDate: 2014-07-14T14:51:24.580Z
Answers.UserDisplayName: Seán O'Grady
Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-14T18:02:15.873Z
Answers.LastActivityDate: 2014-07-14T18:02:15.873Z
Answers.UserDisplayName: Marion Newlevant
Body: <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>
  
Tags: <templating>
Title: Showing a generic image when no image is chosen
ThreadText: # 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 %}
          <a href="{{ entry.url }}" class="flag__img">
              <img src="{{ image.getUrl }}" alt="{{ entry.altText }}" class="profile__image">
          </a>
      {% else %}  
          <p>No image.</p>        
      {% 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 %}
        <a href="{{ entry.url }}" class="flag__img"><img src="{{ image.getUrl() }}" alt="{{ entry.altText }}" class="profile__image" /></a>
    {% else %}
      <p>No image.</p>
    {% 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
  
  ```
  <img src="{{ image ? image.getUrl : 'http://example.com/image.png' }}" />
  
  ```
  
  So you're full snippet would be
  
  ```
  {% for image in entry.illustration %}
          <a href="{{ entry.url }}" class="flag__img">
              <img src="{{ image ? image.getUrl : 'http://example.com/image.png' }}" alt="{{ image.altText ? image.altText : "Default Alt Text" }}" class="profile__image" />
  
          </a>
  {% 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 %}
    <a href="{{ entry.url }}" class="flag__img">
      <img src="{{ image.getUrl }}" alt="{{ entry.altText }}" class="profile__image">
    </a>
  {% else %}
    <p>No image.</p>        
  {% endfor %}
  
  ```
  
  
  ---
  
  