Answers.Body: <p>You can use the <a href="https://docs.craftcms.com/v3/templating/filters.html#group" rel="nofollow noreferrer">group</a> filter</p>
  
  <pre><code>{% set allEntries = craft.entries.section('pets').all() %}
  {% set allEntriesByType = allEntries|group('type') %}
  {% for type, pets in allEntriesByType %}
  
       All Pets of Type {{ type }}
  
       {% for pet in pets %}
           {% include '_partials/animalOrgChart' with {
               title: pet.title,
               subTitle: pet.jobTitle,
               img: pet.headshot|length ? pet.headshot[0],                      
               url: pet.url,
               portrait: true
           } %}        
      {% endfor %}
  
      &lt;hr class="line" /&gt; 
  {% endfor %}
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-18T13:20:11.373Z
Answers.Text: This is great, so simple and concise. For {% set allEntriesByType = allEntries|group('type') %}, I'm targeting a field handle. It works great @Robin. Thanks again.
Answers.UserDisplayName: TRIM
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2018-05-17T13:46:18.090Z
Answers.LastActivityDate: 2018-05-17T13:46:18.090Z
Answers.UserDisplayName: Robin Schambach
Body: <p>I'm looking for shorter way of doing this:</p>
  
  <p>dog dog dog</p>
  
  <p>––––––––––––––––––––––––––</p>
  
  <p>cat cat cat</p>
  
  <p>––––––––––––––––––––––––––</p>
  
  <p>hamster hamster hamster</p>
  
  <p>Currently, I have to run 3 independent loops to group pet types together, and insert a line rule between them.</p>
  
  <p><strong>How can I group pet types together and separate using a line rule?</strong></p>
  
  <pre><code>&lt;div class="row"&gt;
        {% for pet in entries %}
              {% if pet.kind == 'dog' %}
                  {% include '_partials/animalOrgChart' with {
                    title: pet.title,
                    subTitle: pet.jobTitle,
                    img: pet.headshot|length ? pet.headshot[0],                      
                    url: pet.url,
                    portrait: true
                  } %}
              {% endif %}
        {% endfor %}
      &lt;hr class="line" /&gt; 
    &lt;/div&gt;
  &lt;div class="row"&gt;
            {% for pet in entries %}
                  {% if pet.kind == 'cat' %}
                      {% include '_partials/animalOrgChart' with {
                        title: pet.title,
                        subTitle: pet.jobTitle,
                        img: pet.headshot|length ? pet.headshot[0],                      
                        url: pet.url,
                        portrait: true
                      } %}
                  {% endif %}
            {% endfor %}
          &lt;hr class="line" /&gt; 
     &lt;/div&gt;
  &lt;div class="row"&gt;
            {% for pet in entries %}
                  {% if pet.kind == 'hamster' %}
                      {% include '_partials/animalOrgChart' with {
                        title: pet.title,
                        subTitle: pet.jobTitle,
                        img: pet.headshot|length ? pet.headshot[0],                      
                        url: pet.url,
                        portrait: true
                      } %}
                  {% endif %}
            {% endfor %}
          &lt;hr class="line" /&gt; 
     &lt;/div&gt;
  </code></pre>
  
Tags: <loop>
Title: Loop through all entry types, separate each group type by line rule (hr)
ThreadText: # Loop through all entry types, separate each group type by line rule (hr)
  
  (Asked by: username_0 on 2018-05-17)
  
  I'm looking for shorter way of doing this:
  
  dog dog dog
  
  ––––––––––––––––––––––––––
  
  cat cat cat
  
  ––––––––––––––––––––––––––
  
  hamster hamster hamster
  
  Currently, I have to run 3 independent loops to group pet types together, and insert a line rule between them.
  
  **How can I group pet types together and separate using a line rule?**
  
  ```
  <div class="row">
        {% for pet in entries %}
              {% if pet.kind == 'dog' %}
                  {% include '_partials/animalOrgChart' with {
                    title: pet.title,
                    subTitle: pet.jobTitle,
                    img: pet.headshot|length ? pet.headshot[0],                      
                    url: pet.url,
                    portrait: true
                  } %}
              {% endif %}
        {% endfor %}
      <hr class="line" /> 
    </div>
  <div class="row">
            {% for pet in entries %}
                  {% if pet.kind == 'cat' %}
                      {% include '_partials/animalOrgChart' with {
                        title: pet.title,
                        subTitle: pet.jobTitle,
                        img: pet.headshot|length ? pet.headshot[0],                      
                        url: pet.url,
                        portrait: true
                      } %}
                  {% endif %}
            {% endfor %}
          <hr class="line" /> 
     </div>
  <div class="row">
            {% for pet in entries %}
                  {% if pet.kind == 'hamster' %}
                      {% include '_partials/animalOrgChart' with {
                        title: pet.title,
                        subTitle: pet.jobTitle,
                        img: pet.headshot|length ? pet.headshot[0],                      
                        url: pet.url,
                        portrait: true
                      } %}
                  {% endif %}
            {% endfor %}
          <hr class="line" /> 
     </div>
  
  ```
  
  **Tags:** loop
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2018-05-17. Score: 3 | Accepted answer
  
  You can use the [group](https://docs.craftcms.com/v3/templating/filters.html#group) filter
  
  ```
  {% set allEntries = craft.entries.section('pets').all() %}
  {% set allEntriesByType = allEntries|group('type') %}
  {% for type, pets in allEntriesByType %}
  
       All Pets of Type {{ type }}
  
       {% for pet in pets %}
           {% include '_partials/animalOrgChart' with {
               title: pet.title,
               subTitle: pet.jobTitle,
               img: pet.headshot|length ? pet.headshot[0],                      
               url: pet.url,
               portrait: true
           } %}        
      {% endfor %}
  
      <hr class="line" /> 
  {% endfor %}
  
  ```
  
  > **Comments:**
  > **username_0**: This is great, so simple and concise. For {% set allEntriesByType = allEntries|group('type') %}, I'm targeting a field handle. It works great @username_1. Thanks again.  
  
  ---
  
  