<pre><code>{% set myFirstMatrixBlockWithType = entry.blogPostMainSection.type('blogText').one() %}

{{ myFirstMatrixBlockWithType.articleText }} 
</code></pre>

<p>Keep in mind <code>entry.blogPostMainSection</code> is <strong>not</strong> an array of blocks but a <code>Query</code></p>

CC BY-SA 3.0
2018-05-01T14:08:18.423Z
2018-05-01T14:25:49.123Z
2018-05-01T14:25:49.123Z
Robin Schambach
<p>I'm trying to loop through a matrix field that has a few different types of fields in it and different orders. I want to first the first field of a certain type and output only that. Here is what I have so far. </p>

<pre><code>{% for block in entry.blogPostMainSection.all() %}

{% if block.type == "blogText" %}

    {% set articleText =  block.blogArticleText %}

        {% if articleText | length &gt; 100 %}

            {% set articleTextTrim = block.blogArticleText|slice(0, 100) ~ '...' %}

            {{articleTextTrim | striptags}}

        {% else %}

            {{articleText | striptags}}

        {% endif %}

{% endif %}

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

<matrix>
Loop through matrix field find first block of a type
# Loop through matrix field find first block of a type

(Asked by: username_0 on 2018-05-01)

I'm trying to loop through a matrix field that has a few different types of fields in it and different orders. I want to first the first field of a certain type and output only that. Here is what I have so far. 
{% for block in entry.blogPostMainSection.all() %}

{% if block.type == "blogText" %}

    {% set articleText =  block.blogArticleText %}

        {% if articleText | length > 100 %}

            {% set articleTextTrim = block.blogArticleText|slice(0, 100) ~ '...' %}

            {{articleTextTrim | striptags}}

        {% else %}

            {{articleText | striptags}}

        {% endif %}

{% endif %}

{% endfor %}

**Tags:** matrix

---

## 1 answers

### Answer by username_1 on 2018-05-01. Score: 5 | Accepted answer

{% set myFirstMatrixBlockWithType = entry.blogPostMainSection.type('blogText').one() %}

{{ myFirstMatrixBlockWithType.articleText }} 

Keep in mind entry.blogPostMainSection is not an array of blocks but a Query


---

