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

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

&lt;img src="{{ image.getUrl() }}"&gt;  

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

  &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 %}
...


This will help keep your code from repetition and will be easier to maintain in the future :)