Answers.Body: <p>You should be able to do this with Craft's handy <a href="http://buildwithcraft.com/docs/templating/filters#group"><code>group</code></a> filter.</p>
  
  <pre><code>{% set players = entry.myPlayersMatrix %}
  {% set playersGrouped = players|group('myPositionDropdown.label') %}
  
  {% for position, playersInPosition in playersGrouped %}
      &lt;h2&gt;{{ position }}&lt;/h2&gt;
      &lt;ul&gt;
      {% for player in playersInPosition %}
          {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
          &lt;li&gt;
              {{ playerData.fullName }}
              {{ playerData.age }}
              ...
          &lt;/li&gt;
      {% endfor %}
      &lt;/ul&gt;
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T08:19:49.857Z
Answers.Text: Ah - never realised it was possible with matrix fields as well. Straight forward then - thanks!
Answers.UserDisplayName: mmc501
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2015-04-10T06:51:56.870Z
Answers.LastActivityDate: 2015-04-10T06:51:56.870Z
Answers.UserDisplayName: carlcs
Body: <p>Is it possible to group by a field within a matrix field.
  I have a channel of players which holds their details.
  I have a structure for teams which includes a matrix field for a Player.</p>
  
  <p>The Player matrix has 2 fields:</p>
  
  <p>1 - Position (Drop down with: Goalkeeper, Defender, Midfielder)</p>
  
  <p>2 - Entries field linked to Players Channel.</p>
  
  <p>When accessing the matrix is it possible to Group the blocks by the Position field?</p>
  
Tags: <entries><matrix><group>
Title: Group by Field in Matrix Field
ThreadText: # Group by Field in Matrix Field
  
  (Asked by: username_0 on 2015-04-10)
  
  Is it possible to group by a field within a matrix field.
  I have a channel of players which holds their details.
  I have a structure for teams which includes a matrix field for a Player.
  
  The Player matrix has 2 fields:
  
  1 - Position (Drop down with: Goalkeeper, Defender, Midfielder)
  
  2 - Entries field linked to Players Channel.
  
  When accessing the matrix is it possible to Group the blocks by the Position field?
  
  **Tags:** entries, matrix, group
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2015-04-10. Score: 5 | Accepted answer
  
  You should be able to do this with Craft's handy [`group`](http://buildwithcraft.com/docs/templating/filters#group) filter.
  
  ```
  {% set players = entry.myPlayersMatrix %}
  {% set playersGrouped = players|group('myPositionDropdown.label') %}
  
  {% for position, playersInPosition in playersGrouped %}
      <h2>{{ position }}</h2>
      <ul>
      {% for player in playersInPosition %}
          {% set playerData = craft.entries.section('myPlayersChannel').relatedTo(player).first() %}
          <li>
              {{ playerData.fullName }}
              {{ playerData.age }}
              ...
          </li>
      {% endfor %}
      </ul>
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: Ah - never realised it was possible with matrix fields as well. Straight forward then - thanks!  
  
  ---
  
  