Answers.Body: <p>Just answering this for anyone that may come across this in the future as I have...</p>
  
  <p>Could you reuse the group tag?</p>
  
  <pre><code>{% for block in entry.myMatrixField.group(&lt;catgegory here&gt;) %}
      ...
  {% endfor %}
  </code></pre>
  
  <p>You have probably resolved it due to the age, but your answer would be helpful.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-08-20T13:53:57.210Z
Answers.LastActivityDate: 2018-08-20T13:53:57.210Z
Answers.UserDisplayName: Jay
Body: <p>I have a matrix field with a category field. I need to group these matrix items by category and give them headings which I'll use for tabs.</p>
  
  <p>This is how I'd do it for entries but is it possible for matrix?</p>
  
  <pre><code>&lt;ul class="tabs"&gt;
      {% nav category in craft.categories.group('otherAppliances') %}
  
      {% set itemCount = craft.entries.relatedTo(category).total() %}
          {% if itemCount %}
  
              &lt;li rel=""&gt;{{ category.title }}&lt;/li&gt;
  
          {% endif %}
      {% endnav %}
  &lt;/ul&gt;
  </code></pre>
  
  <p>I think my question may be similar to <a href="https://craftcms.stackexchange.com/questions/2524/how-to-query-with-relatedto-of-a-relationship-field-in-a-matrix-field-block">How to query with relatedTo of a Relationship Field in a Matrix Field block</a> but I can't get my head around it.</p>
  
  <p><strong>Matrix setup:</strong></p>
  
  <p><a href="https://i.sstatic.net/iNUGO.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/iNUGO.png" alt="enter image description here"></a></p>
  
Tags: <matrix><categories><relations><relatedto>
Title: Categories within matrix for relatedTo
ThreadText: # Categories within matrix for relatedTo
  
  (Asked by: username_0 on 2017-03-28)
  
  I have a matrix field with a category field. I need to group these matrix items by category and give them headings which I'll use for tabs.
  
  This is how I'd do it for entries but is it possible for matrix?
  
  ```
  <ul class="tabs">
      {% nav category in craft.categories.group('otherAppliances') %}
  
      {% set itemCount = craft.entries.relatedTo(category).total() %}
          {% if itemCount %}
  
              <li rel="">{{ category.title }}</li>
  
          {% endif %}
      {% endnav %}
  </ul>
  
  ```
  
  I think my question may be similar to [How to query with relatedTo of a Relationship Field in a Matrix Field block](https://craftcms.stackexchange.com/questions/2524/how-to-query-with-relatedto-of-a-relationship-field-in-a-matrix-field-block) but I can't get my head around it.
  
  **Matrix setup:**
  
  [![enter image description here](https://i.sstatic.net/iNUGO.png)](https://i.sstatic.net/iNUGO.png)
  
  **Tags:** matrix, categories, relations, relatedto
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-08-20. Score: 1
  
  Just answering this for anyone that may come across this in the future as I have...
  
  Could you reuse the group tag?
  
  ```
  {% for block in entry.myMatrixField.group(<catgegory here>) %}
      ...
  {% endfor %}
  
  ```
  
  You have probably resolved it due to the age, but your answer would be helpful.
  
  
  ---
  
  