Answers.Body: <p>I think the issue here where you are setting your image variable.</p>
  
  <p><code>{% set image = block.image.first() %}</code></p>
  
  <p>This should reference the field handle of the asset you are trying to get the url of, so it should be this instead:</p>
  
  <p><code>{% set image = block.firstImage.first() %}</code></p>
  
  <p>Then where you try and display the image it should be:</p>
  
  <p><code>&lt;img src="{{ image.getUrl() }}"&gt;</code>  </p>
  
  <p>You would then need to update this for the <code>secondImage</code>.</p>
  
  <p>It might be worth mentioning that there is a cleaner way to achieve what you’re after, with just one asset field.</p>
  
  <p>You can upload multiple images to a single asset field, so assuming <code>firstImage</code> has two assets attached, your code could be shortened to the following:</p>
  
  <pre><code>...
  {% elseif block.type == "imageDouble" %}
  
   {# this has two assets attached #}
   {% set images = block.firstImage %}
  
   {% if images and images|length %}
  
    &lt;div class="row imageDouble detail"&gt;
  
      {# Loop through the images #}
      {% for image in images %}
  
        &lt;div class="col-xs-12 col-md-6"&gt;
          &lt;img src="{{ image.getUrl() }}"&gt;
        &lt;/div&gt;
  
      {% endfor %}
  
    &lt;/div&gt;
  
   {% endif %}
  
  {% endif %}
  ...
  </code></pre>
  
  <p>This will help keep your code from repetition and will be easier to maintain in the future :)</p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-28T19:11:52.417Z
Answers.Text: Thanks a million for not only solving my problem but proposing an even cleaner solution!
Answers.UserDisplayName: Jeremy P. Beasley
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-29T12:37:18.073Z
Answers.Text: Not a problem :) glad it helped you out!
Answers.UserDisplayName: Alec Ritson
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-12-08T09:47:31.950Z
Answers.LastActivityDate: 2014-12-08T09:47:31.950Z
Answers.UserDisplayName: Alec Ritson
Body: <p>I'm new to Craft and using Matrix fields.</p>
  
  <p>I've got a matrix field called <code>imageDouble</code> with two child fields called <code>firstImage</code> and <code>secondImage</code>.</p>
  
  <p>The template code I have is returning a 500 error. I want it to display <code>firstImage</code> and <code>secondImage</code> each in their own separate div. Any help with my structure here?</p>
  
  <pre><code>{% for block in entry.body %}
  
      {% if block.type == "text" %}
  
          &lt;div class="row text detail"&gt;
  
              &lt;div class="col-xs-12 col-md-6 col-md-offset-3"&gt;
  
                  &lt;p&gt;{{ block.textContent }}&lt;/p&gt;
  
              &lt;/div&gt;
  
          &lt;/div&gt;
  
      {% elseif block.type == "imageDouble" %}
  
          {% set image = block.image.first() %}
  
              {% if image %}
  
              &lt;div class="row imageDouble detail"&gt;
  
                  &lt;div class="col-xs-12 col-md-6"&gt;
  
                      &lt;img src="{{ firstImage.getUrl() }}"&gt;
  
                  &lt;/div&gt;
  
              {% endif %}
  
          {% set image = block.image.first() %}
  
              {% if image %}
  
                  &lt;div class="col-xs-12 col-md-6"&gt;
  
                      &lt;img src="{{ secondImage.getUrl() }}"&gt;
  
                  &lt;/div&gt;
  
              &lt;/div&gt;
  
              {% endif %}
   {% endfor %}
  </code></pre>
  
Tags: <assets>
Title: How to call two separate images from Matrix field
ThreadText: # How to call two separate images from Matrix field
  
  (Asked by: username_0 on 2014-12-08)
  
  I'm new to Craft and using Matrix fields.
  
  I've got a matrix field called `imageDouble` with two child fields called `firstImage` and `secondImage`.
  
  The template code I have is returning a 500 error. I want it to display `firstImage` and `secondImage` each in their own separate div. Any help with my structure here?
  
  ```
  {% for block in entry.body %}
  
      {% if block.type == "text" %}
  
          <div class="row text detail">
  
              <div class="col-xs-12 col-md-6 col-md-offset-3">
  
                  <p>{{ block.textContent }}</p>
  
              </div>
  
          </div>
  
      {% elseif block.type == "imageDouble" %}
  
          {% set image = block.image.first() %}
  
              {% if image %}
  
              <div class="row imageDouble detail">
  
                  <div class="col-xs-12 col-md-6">
  
                      <img src="{{ firstImage.getUrl() }}">
  
                  </div>
  
              {% endif %}
  
          {% set image = block.image.first() %}
  
              {% if image %}
  
                  <div class="col-xs-12 col-md-6">
  
                      <img src="{{ secondImage.getUrl() }}">
  
                  </div>
  
              </div>
  
              {% endif %}
   {% endfor %}
  
  ```
  
  **Tags:** assets
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2014-12-08. Score: 7 | Accepted answer
  
  I think the issue here where you are setting your image variable.
  
  `{% set image = block.image.first() %}`
  
  This should reference the field handle of the asset you are trying to get the url of, so it should be this instead:
  
  `{% set image = block.firstImage.first() %}`
  
  Then where you try and display the image it should be:
  
  `<img src="{{ image.getUrl() }}">`
  
  You would then need to update this for the `secondImage`.
  
  It might be worth mentioning that there is a cleaner way to achieve what you’re after, with just one asset field.
  
  You can upload multiple images to a single asset field, so assuming `firstImage` has two assets attached, your code could be shortened to the following:
  
  ```
  ...
  {% elseif block.type == "imageDouble" %}
  
   {# this has two assets attached #}
   {% set images = block.firstImage %}
  
   {% if images and images|length %}
  
    <div class="row imageDouble detail">
  
      {# Loop through the images #}
      {% for image in images %}
  
        <div class="col-xs-12 col-md-6">
          <img src="{{ image.getUrl() }}">
        </div>
  
      {% endfor %}
  
    </div>
  
   {% endif %}
  
  {% endif %}
  ...
  
  ```
  
  This will help keep your code from repetition and will be easier to maintain in the future :)
  
  > **Comments:**
  > **username_0**: Thanks a million for not only solving my problem but proposing an even cleaner solution!  
  > **username_1**: Not a problem :) glad it helped you out!  
  
  ---
  
  