<p>I think <code>entry.matrixFieldHandle.type('blockTypeHandle')</code> is what you're looking for. Putting it together, it'd be something like:</p>

<pre><code>{% set tag = entry.keywords %}
{% set relatedEntries = craft.entries.relatedTo(tag).id('not ' ~ entry.id).limit(8) %}

{% for relatedEntry in relatedEntries %}

    {% set matrixBlock = relatedEntry.matrixFieldHandle.type('blockTypeHandle').first() %}

    {% if matrixBlock %}

        {% set asset = matrixBlock.imageFieldHandle.first() %}

        {% if asset %}

            &lt;h1&gt;{{ relatedEntry.title }}&lt;/h1&gt;
            {{ asset.img }}

        {% endif %}

    {% endif %}

{% endfor %}
</code></pre>

CC BY-SA 3.0
2015-04-05T09:19:54.290Z
Somehow, I had it like that, before I've posted the question, except I moved the element criteria model outside the `for` loop to save DB query, I think. However I do, I get either the first image of all asset's images, or either none image. Sometimes I get message error -  object couldn't be converted to string.
Dominik Krulak
CC BY-SA 3.0
2015-04-07T11:01:56.353Z
At the first and this time, it's correct @Adam Gilleard. I was extending within `if` statement `elseif`, which was throwing me errors. Now it's fixed. Thanks
Dominik Krulak
CC BY-SA 3.0
2015-04-04T17:33:38.600Z
2015-04-05T17:11:49.607Z
2015-04-05T17:11:49.607Z
Adam Gilleard
<p>I want to display on entry view page, related entries to current tags.
So far, I came to displaying basic entry's object, but I don't know How to get in matrix field and pull the first image.</p>

<p>Images are stored in <code>matrixFieldHandle</code> -> <code>blockTypeHandle</code> -> <code>imageFieldHandle</code>.</p>

<p><strong>For outputting related entries to current tags I use:</strong></p>

<pre><code>{# Set ECM for related entries to current tags #}
{% set tag = entry.keywords %}
{% set relatedEntries = craft.entries.relatedTo(tag).id('not ' ~ entry.id).limit(8).find() %}


{% for entry in relatedEntries %}
    {{ entry.title }}
{% endfor %}
</code></pre>

<matrix><relations>
Display first image from matrix field of a related entry to current tags
# Display first image from matrix field of a related entry to current tags

(Asked by: username_0 on 2015-04-04)

I want to display on entry view page, related entries to current tags.
So far, I came to displaying basic entry's object, but I don't know How to get in matrix field and pull the first image.
Images are stored in matrixFieldHandle -> blockTypeHandle -> imageFieldHandle.
For outputting related entries to current tags I use:
{# Set ECM for related entries to current tags #}
{% set tag = entry.keywords %}
{% set relatedEntries = craft.entries.relatedTo(tag).id('not ' ~ entry.id).limit(8).find() %}


{% for entry in relatedEntries %}
    {{ entry.title }}
{% endfor %}

**Tags:** matrix, relations


---

## 1 answers

### Answer by username_1 on 2015-04-04. Score: 2 | Accepted answer

I think entry.matrixFieldHandle.type('blockTypeHandle') is what you're looking for. Putting it together, it'd be something like:
{% set tag = entry.keywords %}
{% set relatedEntries = craft.entries.relatedTo(tag).id('not ' ~ entry.id).limit(8) %}

{% for relatedEntry in relatedEntries %}

    {% set matrixBlock = relatedEntry.matrixFieldHandle.type('blockTypeHandle').first() %}

    {% if matrixBlock %}

        {% set asset = matrixBlock.imageFieldHandle.first() %}

        {% if asset %}

            {{ relatedEntry.title }}
            {{ asset.img }}

        {% endif %}

    {% endif %}

{% endfor %}

> **Comments:**
> **username_0**: Somehow, I had it like that, before I've posted the question, except I moved the element criteria model outside the `for` loop to save DB query, I think. However I do, I get either the first image of all asset's images, or either none image. Sometimes I get message error -  object couldn't be converted to string.  
> **username_0**: At the first and this time, it's correct @username_1. I was extending within `if` statement `elseif`, which was throwing me errors. Now it's fixed. Thanks  

---

