<p>You can limit which blocks you want by type and only show the first of each, if they exist. Something like this might do the trick:</p>

<pre><code>{% for entry in craft.entries.section('blog').limit(3).find() %}
    &lt;div class="col-8  {% if loop.last %}last{% endif %}"&gt;

        {% set textBlock = entry.blogBody.type('text').first() %}
        {% set imgBlock = entry.blogBody.type('blogimage').first() %}

        {% if textBlock %}
            {{ textBlock.text|hacksaw(chars='100', append='...') }}
        {% endif %}

        {% if imgBlock %}
              &lt;img src="{{ imgBlock.image[0].getUrl() }}" alt=""/&gt;
        {% endif %}
    &lt;/div&gt;
{% endfor %}

&lt;/div&gt;

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

CC BY-SA 3.0
2015-10-25T08:27:36.787Z
Thanks for the reply. I get a Recoverable error : Object of class Craft\ElementCriteriaModel could not be converted to string error for this
sarah3585
CC BY-SA 3.0
2015-10-25T16:24:39.350Z
@sarah3585 just made an edit - forgot to add `.text` to your textBlock matrix block. I also changed `.limit(1)` to `.first()`. Let me know if that works!
Aaron Berkowitz
CC BY-SA 3.0
2015-10-24T17:21:29.407Z
2015-10-25T16:22:36.987Z
2015-10-25T16:22:36.987Z
Aaron Berkowitz
<p>I'm using Matrix fields for blog posts. These are made up of text and image block types. I want to pull in only the first image block and a snippet of text from the first text block into the blogs index page for listing the entries. </p>

<p>Adding limit(1) to each block type didn't work.</p>

<pre><code>{% for entry in craft.entries.section('blog').limit(3).find() %}
&lt;div class="col-8  {% if loop.last %}last{% endif %}"&gt;

    {% for block in entry.blogBody %}

    {% switch block.type %}

      {% case "text" %}
      {{ block.text|hacksaw(chars='100', append='...') }}

      {% case "blogimage" %}
       {% for asset in block.image %}
          &lt;img src="{{ asset.getUrl() }}" alt=""/&gt;
      {% endfor %}

 {% endswitch %}

{% endfor %}
&lt;/div&gt;
{% endfor %}

&lt;/div&gt;

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

<matrix><block-types><limit>
Matrix - using Limit on block types
# Matrix - using Limit on block types

(Asked by: username_0 on 2015-10-24)

I'm using Matrix fields for blog posts. These are made up of text and image block types. I want to pull in only the first image block and a snippet of text from the first text block into the blogs index page for listing the entries. 
Adding limit(1) to each block type didn't work.
{% for entry in craft.entries.section('blog').limit(3).find() %}


    {% for block in entry.blogBody %}

    {% switch block.type %}

      {% case "text" %}
      {{ block.text|hacksaw(chars='100', append='...') }}

      {% case "blogimage" %}
       {% for asset in block.image %}
          
      {% endfor %}

 {% endswitch %}

{% endfor %}

{% endfor %}



{% endblock %}

**Tags:** matrix, block-types, limit


---

## 1 answers

### Answer by username_1 on 2015-10-24. Score: 4 | Accepted answer

You can limit which blocks you want by type and only show the first of each, if they exist. Something like this might do the trick:
{% for entry in craft.entries.section('blog').limit(3).find() %}
    

        {% set textBlock = entry.blogBody.type('text').first() %}
        {% set imgBlock = entry.blogBody.type('blogimage').first() %}

        {% if textBlock %}
            {{ textBlock.text|hacksaw(chars='100', append='...') }}
        {% endif %}

        {% if imgBlock %}
              
        {% endif %}
    
{% endfor %}



{% endblock %}

> **Comments:**
> **username_0**: Thanks for the reply. I get a Recoverable error : Object of class Craft\ElementCriteriaModel could not be converted to string error for this  
> **username_1**: @username_0 just made an edit - forgot to add `.text` to your textBlock matrix block. I also changed `.limit(1)` to `.first()`. Let me know if that works!  

---

