2

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 %}
4
{% set myFirstMatrixBlockWithType = entry.blogPostMainSection.type('blogText').one() %}

{{ myFirstMatrixBlockWithType.articleText }} 

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

| improve this answer | |

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.