Answers.Body: <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>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-25T08:27:36.787Z
Answers.Text: Thanks for the reply. I get a Recoverable error : Object of class Craft\ElementCriteriaModel could not be converted to string error for this
Answers.UserDisplayName: sarah3585
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-25T16:24:39.350Z
Answers.Text: @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!
Answers.UserDisplayName: Aaron Berkowitz
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-10-24T17:21:29.407Z
Answers.LastActivityDate: 2015-10-25T16:22:36.987Z
Answers.LastEditDate: 2015-10-25T16:22:36.987Z
Answers.UserDisplayName: Aaron Berkowitz
Body: <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>
  
Tags: <matrix><block-types><limit>
Title: Matrix - using Limit on block types
ThreadText: # 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() %}
  <div class="col-8  {% if loop.last %}last{% endif %}">
  
      {% for block in entry.blogBody %}
  
      {% switch block.type %}
  
        {% case "text" %}
        {{ block.text|hacksaw(chars='100', append='...') }}
  
        {% case "blogimage" %}
         {% for asset in block.image %}
            <img src="{{ asset.getUrl() }}" alt=""/>
        {% endfor %}
  
   {% endswitch %}
  
  {% endfor %}
  </div>
  {% endfor %}
  
  </div>
  
  {% 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() %}
      <div class="col-8  {% if loop.last %}last{% endif %}">
  
          {% 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 %}
                <img src="{{ imgBlock.image[0].getUrl() }}" alt=""/>
          {% endif %}
      </div>
  {% endfor %}
  
  </div>
  
  {% 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!  
  
  ---
  
  