title: Twig Loop Grouping
body: <p>Lets say I have some data called 'people' in an array past into a twig template like this:</p>
  
  <pre><code>firstname | surname | colour
  Fred        Smith     Blue
  James       Holmes    Red
  Sarah       Fisher    Blue
  Chrstine    Jenkins   Yellow
  Sid         Wells     Red
  Cory        Simpson   Blue
  Laura       Jones     Yellow
  </code></pre>
  
  <p>With this data i need to group them by the 'colour' column.  by wrapping a div around the users based on there colour.  e.g</p>
  
  <pre><code>&lt;div class="colour_container"&gt;
  Fred Smith - Blue&lt;br&gt;
  Sarah Fisher - Blue&lt;br&gt;
  Cory Simpson - Blue&lt;br&gt;
  &lt;/div&gt;
  
  &lt;div class="colour_container"&gt;
  James Holmes - Red&lt;br&gt;
  Sid Wells - Red&lt;br&gt;
  &lt;/div&gt; 
  
  &lt;div class="colour_container"&gt;
  Christine Jenkins - Yellow&lt;br&gt;
  Laura Jones - Yellow&lt;br&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>now if I use a twig loop, it puts the div around each name rather than grouping them by colour.  Whats the easiest way to get the above output?  Ive tried all sorts of things in the loop but I am struggling.</p>
  
  <pre><code>{% for p in people %}
     &lt;div class="colour_container"&gt;
         {{ p.firstname }} {{ p.surname }} - {{ p.colour }}
     &lt;/div&gt;
  {% endfor %}
  </code></pre>
  
  <p>I need it to somehow loop through unique colour values first then loop through the names that belong to that colour.</p>