<p>You're almost there. </p>

<p>Every block returns a MatrixBlockModel, so you have to reference your block when getting the attributes:</p>

<pre><code>{% for block in entry.threeHomepageImages.type('images') %}
    &lt;h2&gt;{{ block.imageTitle }}&lt;/h2&gt;
    {# Save images to variable for reuse #}
    {% set image = block.image %}
    {# Check if there is any images #}
    {% if image | length %}
        {# Get url #}
        {% set image = image.first().getUrl() %}
        &lt;img src="{{ image }}" alt="{{ block.alt }}" /&gt; 
    {% endif %}
{% endfor %}
</code></pre>

CC BY-SA 3.0
2014-09-17T15:52:35.337Z
2014-09-17T16:46:44.283Z
2014-09-17T16:46:44.283Z
Fred Carlsen
<p>It looks like you're pretty close, but those field names need to be called as attributes on <code>block</code>:</p>

<pre><code>{% for block in entry.threeHomepageImages.type('images') %}
    {% if block.image|length %}
        {{ block.image.first }}
    {% endif %}
    {{ block.alt }} {{ block.imageTitle }}
{% endfor %}
</code></pre>

<p>I'm assuming your <code>image</code> field is an <a href="http://buildwithcraft.com/docs/assets-fields#examples" rel="noreferrer">Assets Field</a> here, so you need to first check that any exist, then select the first one.</p>

CC BY-SA 3.0
2014-09-17T15:52:56.740Z
2014-09-17T15:52:56.740Z
Mike Pepper
<p>I have looked at documentation and I still can't figure out how to output the matrix to my template.</p>

<p>The Field handle name is: <strong>threeHomepageImages</strong></p>

<p>The Block type handle name is: <strong>images</strong></p>

<p>The Fields names are: <strong>image</strong>, <strong>alt</strong>, and <strong>imageTitle</strong></p>

<p>I have the following and tried a few combinations, but no luck. Any help is much appreciated.</p>

<pre><code>{% for block in entry.threeHomepageImages.type('images') %}
    {{ image }} {{ alt }} {{ imageTitle }}
{% endfor %}
</code></pre>

<templating><matrix><forloop>
Outputting Matrix Loop in Template
# Outputting Matrix Loop in Template

(Asked by: username_0 on 2014-09-17)

I have looked at documentation and I still can't figure out how to output the matrix to my template.
The Field handle name is: threeHomepageImages
The Block type handle name is: images
The Fields names are: image, alt, and imageTitle
I have the following and tried a few combinations, but no luck. Any help is much appreciated.
{% for block in entry.threeHomepageImages.type('images') %}
    {{ image }} {{ alt }} {{ imageTitle }}
{% endfor %}

**Tags:** templating, matrix, forloop

---

## 2 answers

### Answer by username_2 on 2014-09-17. Score: 5 | Accepted answer

It looks like you're pretty close, but those field names need to be called as attributes on block:
{% for block in entry.threeHomepageImages.type('images') %}
    {% if block.image|length %}
        {{ block.image.first }}
    {% endif %}
    {{ block.alt }} {{ block.imageTitle }}
{% endfor %}

I'm assuming your image field is an Assets Field here, so you need to first check that any exist, then select the first one.


---

### Answer by username_1 on 2014-09-17. Score: 5

You're almost there. 
Every block returns a MatrixBlockModel, so you have to reference your block when getting the attributes:
{% for block in entry.threeHomepageImages.type('images') %}
    {{ block.imageTitle }}
    {# Save images to variable for reuse #}
    {% set image = block.image %}
    {# Check if there is any images #}
    {% if image | length %}
        {# Get url #}
        {% set image = image.first().getUrl() %}
         
    {% endif %}
{% endfor %}


---

