Answers.Body: <p>In my Case i had to add .all() at the end then it worked with the Verison
  &quot;Craft Solo 4.1.4.1&quot;</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-07-21T15:36:00.070Z
Answers.LastActivityDate: 2022-07-21T15:36:00.070Z
Answers.UserDisplayName: Nik Lussy
Answers.Body: <p>You can grab a specific block type in Matrix by doing this:</p>
  
  <pre><code>{% for block in entry.myMatrixField.type('typeOne') %}
      {{ block.text | markdown }}
  {% endfor %}
  </code></pre>
  
  <p>If you wanted to know the number of blocks of a certain type, you can do:</p>
  
  <pre><code>{% set blocks = entry.myMatrixField.type('typeOne') %}
  {{ blocks | length }}
  </code></pre>
  
  <p>If you want to search for multiple block types, you can do this:</p>
  
  <pre><code>{% set blocks = entry.myMatrixField.type('typeOne, typeTwo') %}
  </code></pre>
  
  <p>For your specific example, it would look like this:</p>
  
  <pre><code>{% set typeOneBlocks = entry.myMatrixField.type('typeOne') %}
  
  {% if typeOneBlocks | length %}
      &lt;div class="divAWrapper"&gt;
          {% for block in typeOneBlocks %}
              &lt;div class="divA"&gt;{# do stuff #}&lt;/div&gt;
          {% endfor %}
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-10T19:59:16.403Z
Answers.Text: 6 minutes for a reply? Seriously, you guys are amazing. I'm not sure if I missed the documentation or if you just added it, but thanks for the quick help. http://buildwithcraft.com/docs/matrix-fields
Answers.UserDisplayName: idahotallpaul
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-10T20:21:04.437Z
Answers.Text: It's been in the docs for awhile. :)
Answers.UserDisplayName: Brad Bell
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-01-08T14:02:17.747Z
Answers.Text: @BradBell I 'd like to filter matrix block by category field. could you please guide for the same.
Answers.UserDisplayName: Bhashkar Yadav
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-10T19:42:55.633Z
Answers.LastActivityDate: 2014-07-10T19:42:55.633Z
Answers.UserDisplayName: Brad Bell
Body: <p>Is there a way to filter a matrix by block type, or get a count of how many items there are of a certain type? Can't find a syntax example.</p>
  
  <p>I created a matrix with two blocks. In pseudo code, basically what I want to do is this:</p>
  
  <pre><code>{% set typeOneBlocks = theMatrix blocks where type == "typeOne" %}
  
  {% if typeOneBlocks != null %}
      &lt;div class="divAWrapper"&gt;
          {% for block in typeOneBlocks %}
              &lt;div class="divA"&gt;{# do stuff #}&lt;/div&gt;
          {% endfor %}
      &lt;/div&gt;
  {% endif %}
  </code></pre>
  
  <p>Same with <code>typeTwo</code> blocks. If there are no items of one type or the other, I don't want to create that container and have it sitting empty. </p>
  
  <p>If there is not a way to filter or get a count, I'd have to use for loops to increment vars for how many of each block type there are and then act based on those counts. Seems there should be a simpler way.</p>
  
Tags: <templating><matrix><forloop>
Title: How do you filter matrix blocks by type?
ThreadText: # How do you filter matrix blocks by type?
  
  (Asked by: username_0 on 2014-07-10)
  
  Is there a way to filter a matrix by block type, or get a count of how many items there are of a certain type? Can't find a syntax example.
  
  I created a matrix with two blocks. In pseudo code, basically what I want to do is this:
  
  ```
  {% set typeOneBlocks = theMatrix blocks where type == "typeOne" %}
  
  {% if typeOneBlocks != null %}
      <div class="divAWrapper">
          {% for block in typeOneBlocks %}
              <div class="divA">{# do stuff #}</div>
          {% endfor %}
      </div>
  {% endif %}
  
  ```
  
  Same with `typeTwo` blocks. If there are no items of one type or the other, I don't want to create that container and have it sitting empty.
  
  If there is not a way to filter or get a count, I'd have to use for loops to increment vars for how many of each block type there are and then act based on those counts. Seems there should be a simpler way.
  
  **Tags:** templating, matrix, forloop
  
  
  ---
  
  ## 2 answers
  
  ### Answer by username_2 on 2014-07-10. Score: 20 | Accepted answer
  
  You can grab a specific block type in Matrix by doing this:
  
  ```
  {% for block in entry.myMatrixField.type('typeOne') %}
      {{ block.text | markdown }}
  {% endfor %}
  
  ```
  
  If you wanted to know the number of blocks of a certain type, you can do:
  
  ```
  {% set blocks = entry.myMatrixField.type('typeOne') %}
  {{ blocks | length }}
  
  ```
  
  If you want to search for multiple block types, you can do this:
  
  ```
  {% set blocks = entry.myMatrixField.type('typeOne, typeTwo') %}
  
  ```
  
  For your specific example, it would look like this:
  
  ```
  {% set typeOneBlocks = entry.myMatrixField.type('typeOne') %}
  
  {% if typeOneBlocks | length %}
      <div class="divAWrapper">
          {% for block in typeOneBlocks %}
              <div class="divA">{# do stuff #}</div>
          {% endfor %}
      </div>
  {% endif %}
  
  ```
  
  > **Comments:**
  > **username_0**: 6 minutes for a reply? Seriously, you guys are amazing. I'm not sure if I missed the documentation or if you just added it, but thanks for the quick help. http://buildwithcraft.com/docs/matrix-fields  
  > **username_2**: It's been in the docs for awhile. :)  
  > **username_3**: @username_2 I 'd like to filter matrix block by category field. could you please guide for the same.  
  
  ---
  
  ### Answer by username_1 on 2022-07-21. Score: 1
  
  In my Case i had to add .all() at the end then it worked with the Verison
  "Craft Solo 4.1.4.1"
  
  
  ---
  
  