Answers.Body: <p>I got it using the 'group' filter at : <a href="http://buildwithcraft.com/docs/templating/filters#group" rel="nofollow">http://buildwithcraft.com/docs/templating/filters#group</a></p>
  
  <p>Thanks to Steve Abraham for pointing me in the right direction. My code that seems to work is:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set companyHistory = craft.entries.section('about').slug('company-history').first() %}
  {% set allEntriesByYear = companyHistory.children.type('history') | group('date.year') %}
  
  {% for year, entriesInYear in allEntriesByYear %}
      &lt;h2&gt;{{ year }}&lt;/h2&gt;
      {% for moment in entriesInYear %}
          &lt;li&gt;{{ moment.title }}&lt;/li&gt;
      {% endfor %}
  {% endfor %}
  </code></pre>
  
  <p>Let me know if there is an even better solution. </p>
  
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T14:23:55.437Z
Answers.Text: Superb, and I didn't even have to answer. ;)
Answers.UserDisplayName: Steve Abraham
Answers.ContentLicense: CC BY-SA 3.0
Answers.CreationDate: 2014-07-07T14:22:31.187Z
Answers.LastActivityDate: 2014-07-08T22:03:14.733Z
Answers.LastEditDate: 2014-07-08T22:03:14.733Z
Answers.UserDisplayName: Christopher Healey
Body: <p>I'm outputting a timeline for company history and i'd like to add a graphic for the Year before the first entry of each year. My current code is as follows:</p>
  
  <pre class="lang-twig prettyprint-override"><code>{% set companyHistory = craft.entries.section('about').slug('company-history').first() %}
  
  {% for moment in companyHistory.children.type('history') %}
      &lt;li&gt;{{ moment.title }}&lt;/li&gt;
  {% endfor %}
  </code></pre>
  
  <p>My date field is simply called 'date'. How might I go about this with the fewest possible DB queries?</p>
  
Tags: <entries><date>
Title: Do something if first entry of a year
ThreadText: # Do something if first entry of a year
  
  (Asked by: username_0 on 2014-07-07)
  
  I'm outputting a timeline for company history and i'd like to add a graphic for the Year before the first entry of each year. My current code is as follows:
  
  ```twig
  {% set companyHistory = craft.entries.section('about').slug('company-history').first() %}
  
  {% for moment in companyHistory.children.type('history') %}
      <li>{{ moment.title }}</li>
  {% endfor %}
  
  ```
  
  My date field is simply called 'date'. How might I go about this with the fewest possible DB queries?
  
  **Tags:** entries, date
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_0 on 2014-07-07. Score: 3 | Accepted answer
  
  I got it using the 'group' filter at : <http://buildwithcraft.com/docs/templating/filters#group>
  
  Thanks to username_1 username_1 for pointing me in the right direction. My code that seems to work is:
  
  ```twig
  {% set companyHistory = craft.entries.section('about').slug('company-history').first() %}
  {% set allEntriesByYear = companyHistory.children.type('history') | group('date.year') %}
  
  {% for year, entriesInYear in allEntriesByYear %}
      <h2>{{ year }}</h2>
      {% for moment in entriesInYear %}
          <li>{{ moment.title }}</li>
      {% endfor %}
  {% endfor %}
  
  ```
  
  Let me know if there is an even better solution.
  
  > **Comments:**
  > **username_1**: Superb, and I didn't even have to answer. ;)  
  
  ---
  
  