Answers.Body: <p>You can test if your <code>first()</code> method returns an asset model. 
  And depending on that have different image URLs, the (transformed) asset's one or the URL of your placholder image.</p>
  
  <pre><code>{% set image = block.mx_peoplePhoto.first() %}
  {% set imageUrl = image ? image.url('500x500') : url('images/_static/placeholder.jpg') %}
  
  &lt;img src="{{ imageUrl }}"&gt;
  </code></pre>
  
  <p>You could also consider to get that placeholder image from a <a href="http://buildwithcraft.com/docs/globals" rel="nofollow">global set</a>.</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-02T09:10:34.437Z
Answers.Text: Thanks for taking a look.  Something very bizarre happening, it's only pulling through a replacement image for the most recently added entry??  All previous entries seem to be ignored.  I've cleared caches.
Answers.UserDisplayName: Martin
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T20:55:59.103Z
Answers.LastActivityDate: 2015-09-01T20:55:59.103Z
Answers.UserDisplayName: carlcs
Answers.Body: <p>I have a macro that I use for all images that falls back to our logo if an image is not supplied to it for whatever reason.</p>
  
  <pre><code>{% macro imageTransform(image, transform, caption, extraHTML) %}
  {# Fallback to our logo if the image is null... #}
  {% if not image|length %}
      {% set image = craft.assets.id('84').first() %}
  {% endif %}
  &lt;img src="{{ image.getUrl( transform ) }}" width="{{ image.getWidth( transform ) }}" height="{{ image.getHeight( transform ) }}" title="{{ caption|default('') }}" alt="{{ caption|default('') }}"{% if extraHTML %} {{ extraHTML }}{% endif %}&gt;    
  {% endmacro %}  
  </code></pre>
  
  <p>And here is  a sample use of it</p>
  
  <pre><code>{% for row in imagesTable %}
      &lt;div class="gallery-block__item"&gt;
          {% set image = row.image.first() %}             
          {% set caption = row.caption %}
          {% set transform = 'fit500By500' %}
          {% set extraHTML = "class=gallery-block__item-image" %}
          {{ imageLib.imageTransform( image, transform, caption, extraHTML) }}
          &lt;span class="gallery-block__caption"&gt;{{ row.caption }}&lt;/span&gt;
      &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>(Note the lack of quotes on the extraHTML BTW)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-09-01T23:29:17.190Z
Answers.LastActivityDate: 2015-09-02T03:52:24.803Z
Answers.LastEditDate: 2015-09-02T03:52:24.803Z
Answers.UserDisplayName: Jeremy Daalder
Body: <p>I've looked at and tried a couple of solutions on here but struggling to apply them to my circumstance.</p>
  
  <p>Below is my current code.  I would like a 'default' asset (image) to be used if one hasn't been specified by the admin.  This is so that the front end doesn't have gaps in the gallery.</p>
  
  <pre><code>&lt;ul id="photListing"&gt;
  {% cache %}
    {% for entry in craft.entries.section('people').find() %}
    &lt;li&gt;
      &lt;a href="{{ entry.url }}"&gt;
        &lt;figure&gt;
        {% for block in entry.basicProfileInfo %}
        {% set varBarrPic = block.mx_peoplePhoto.first() %}
          &lt;img src="{{ varBarrPic.url }}" alt=""&gt;
            &lt;figcaption&gt;&lt;span&gt;{{ block.mx_positionWithinBusiness }}&lt;/span&gt; {{ entry.title }}&lt;/figcaption&gt;
        {% endfor %}
        &lt;/figure&gt;
      &lt;/a&gt;
    &lt;/li&gt;
    {% endfor %}
  {% endcache %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>I hope this is a simple solution.</p>
  
  <p>Many thanks</p>
  
  <p>Martin</p>
  
Tags: <assets><image>
Title: Output a default asset if one hasn't been specified
ThreadText: # Output a default asset if one hasn't been specified
  
  (Asked by: username_0 on 2015-09-01)
  
  I've looked at and tried a couple of solutions on here but struggling to apply them to my circumstance.
  
  Below is my current code. I would like a 'default' asset (image) to be used if one hasn't been specified by the admin. This is so that the front end doesn't have gaps in the gallery.
  
  ```
  <ul id="photListing">
  {% cache %}
    {% for entry in craft.entries.section('people').find() %}
    <li>
      <a href="{{ entry.url }}">
        <figure>
        {% for block in entry.basicProfileInfo %}
        {% set varBarrPic = block.mx_peoplePhoto.first() %}
          <img src="{{ varBarrPic.url }}" alt="">
            <figcaption><span>{{ block.mx_positionWithinBusiness }}</span> {{ entry.title }}</figcaption>
        {% endfor %}
        </figure>
      </a>
    </li>
    {% endfor %}
  {% endcache %}
  </ul>
  
  ```
  
  I hope this is a simple solution.
  
  Many thanks
  
  username_0
  
  **Tags:** assets, image
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_1 on 2015-09-01. Score: 1
  
  You can test if your `first()` method returns an asset model.
  And depending on that have different image URLs, the (transformed) asset's one or the URL of your placholder image.
  
  ```
  {% set image = block.mx_peoplePhoto.first() %}
  {% set imageUrl = image ? image.url('500x500') : url('images/_static/placeholder.jpg') %}
  
  <img src="{{ imageUrl }}">
  
  ```
  
  You could also consider to get that placeholder image from a [global set](http://buildwithcraft.com/docs/globals).
  
  > **Comments:**
  > **username_0**: Thanks for taking a look.  Something very bizarre happening, it's only pulling through a replacement image for the most recently added entry??  All previous entries seem to be ignored.  I've cleared caches.  
  
  ---
  
  ### Answer by username_2 on 2015-09-01. Score: 0
  
  I have a macro that I use for all images that falls back to our logo if an image is not supplied to it for whatever reason.
  
  ```
  {% macro imageTransform(image, transform, caption, extraHTML) %}
  {# Fallback to our logo if the image is null... #}
  {% if not image|length %}
      {% set image = craft.assets.id('84').first() %}
  {% endif %}
  <img src="{{ image.getUrl( transform ) }}" width="{{ image.getWidth( transform ) }}" height="{{ image.getHeight( transform ) }}" title="{{ caption|default('') }}" alt="{{ caption|default('') }}"{% if extraHTML %} {{ extraHTML }}{% endif %}>    
  {% endmacro %}  
  
  ```
  
  And here is a sample use of it
  
  ```
  {% for row in imagesTable %}
      <div class="gallery-block__item">
          {% set image = row.image.first() %}             
          {% set caption = row.caption %}
          {% set transform = 'fit500By500' %}
          {% set extraHTML = "class=gallery-block__item-image" %}
          {{ imageLib.imageTransform( image, transform, caption, extraHTML) }}
          <span class="gallery-block__caption">{{ row.caption }}</span>
      </div>
  {% endfor %}
  
  ```
  
  (Note the lack of quotes on the extraHTML BTW)
  
  
  ---
  
  