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

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.


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') %}
    <h2>{{ block.imageTitle }}</h2>
    {# 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() %}
        <img src="{{ image }}" alt="{{ block.alt }}" /> 
    {% endif %}
{% endfor %}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.