<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>

CC BY-SA 3.0
2014-12-28T19:11:52.417Z
Thanks a million for not only solving my problem but proposing an even cleaner solution!
Jeremy P. Beasley
CC BY-SA 3.0
2014-12-29T12:37:18.073Z
Not a problem :) glad it helped you out!
Alec Ritson
CC BY-SA 3.0
2014-12-08T09:47:31.950Z
2014-12-08T09:47:31.950Z
Alec Ritson
<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>

<assets>
How to call two separate images from Matrix field
# 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" %}

        

            

                {{ block.textContent }}

            

        

    {% elseif block.type == "imageDouble" %}

        {% set image = block.image.first() %}

            {% if image %}

            

                

                    

                

            {% endif %}

        {% set image = block.image.first() %}

            {% if image %}

                

                    

                

            

            {% 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:
 
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 %}

  

    {# Loop through the images #}
    {% for image in images %}

      
        
      

    {% endfor %}

  

 {% 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!  

---

