Body: <p>I'm trying to create an archive of PDF newsletters in Craft 3. I want to create a list of entries sorted by month and year. Then each year would appear separately. Finally, I want each asset within the entry to be linked to the month name for download. </p>
  
  <p>I can get each entry to output by month - but it is not separating by year. I'm also not certain how to call just the asset in this loop. Would it be better to link to an entry and then show the asset there?</p>
  
  <p>Here's what I have so far:</p>
  
  <pre><code>{# all entries sorted by year/month   #}
  {% set allEntries = craft.entries.section('sectionName').limit(null).orderBy('postDate desc') %}
  
  
    {% for year, entriesInYear in allEntries.all() | group("postDate.year") %}
        &lt;div class="w-col w-col-medium-3 w-col-3" data-mh="years"&gt;
          &lt;h3&gt;{{ year }}&lt;/h3&gt;
  
          {% for month, entries in entriesInYear | group("postDate|date('F')" ) %}
  
              {% for entry in entries %}
                  {% for asset in entry.file %}&lt;a href="{{ asset.getUrl }}" class="w-inline-block"&gt;
                  {% endfor %}
              {% endfor %} 
  
                  {{ month }}&lt;/a&gt; 
  
          {% endfor %}
  
        &lt;/div&gt;
    {% endfor %}
  </code></pre>
  
  <p>This outputs:</p>
  
  <pre><code>    &lt;div class="w-col w-col-medium-3 w-col-3" data-mh="years"&gt;
          &lt;h3&gt;&lt;/h3&gt;
  
  &lt;a href="/media/newsletter-06-2018.pdf" class="w-inline-block"&gt;             &lt;a href="/media/newsletter-06-2017.pdf" class="w-inline-block"&gt;             &lt;a href="/media/newsletter-06-2016.pdf" class="w-inline-block"&gt; 
  
  June&lt;/a&gt; 
  
  &lt;a href="/media/newsletter-05-2018.pdf" class="w-inline-block"&gt;             &lt;a href="/media/newsletter-05-2017.pdf" class="w-inline-block"&gt;             &lt;a href="/media/newsletter-05-2016.pdf" class="w-inline-block"&gt; 
  
  May&lt;/a&gt; 
  
  &lt;/div&gt;
  </code></pre>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-07T17:49:47.403Z
Comments.Text: can you edit with input/output?
Comments.UserDisplayName: Clark Nelson
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2018-06-08T02:48:25.980Z
Comments.Text: ok updated with output. Not seeing year and months are all grouped together instead of in separate years.
Comments.UserDisplayName: glider
Tags: <craft3><archives>
Title: Creating an archive with linked asset
ThreadText: # Creating an archive with linked asset
  
  (Asked by: username_0 on 2018-06-07)
  
  I'm trying to create an archive of PDF newsletters in Craft 3. I want to create a list of entries sorted by month and year. Then each year would appear separately. Finally, I want each asset within the entry to be linked to the month name for download.
  
  I can get each entry to output by month - but it is not separating by year. I'm also not certain how to call just the asset in this loop. Would it be better to link to an entry and then show the asset there?
  
  Here's what I have so far:
  
  ```
  {# all entries sorted by year/month   #}
  {% set allEntries = craft.entries.section('sectionName').limit(null).orderBy('postDate desc') %}
  
    {% for year, entriesInYear in allEntries.all() | group("postDate.year") %}
        <div class="w-col w-col-medium-3 w-col-3" data-mh="years">
          <h3>{{ year }}</h3>
  
          {% for month, entries in entriesInYear | group("postDate|date('F')" ) %}
  
              {% for entry in entries %}
                  {% for asset in entry.file %}<a href="{{ asset.getUrl }}" class="w-inline-block">
                  {% endfor %}
              {% endfor %} 
  
                  {{ month }}</a> 
  
          {% endfor %}
  
        </div>
    {% endfor %}
  
  ```
  
  This outputs:
  
  ```
      <div class="w-col w-col-medium-3 w-col-3" data-mh="years">
          <h3></h3>
  
  <a href="/media/newsletter-06-2018.pdf" class="w-inline-block">             <a href="/media/newsletter-06-2017.pdf" class="w-inline-block">             <a href="/media/newsletter-06-2016.pdf" class="w-inline-block"> 
  
  June</a> 
  
  <a href="/media/newsletter-05-2018.pdf" class="w-inline-block">             <a href="/media/newsletter-05-2017.pdf" class="w-inline-block">             <a href="/media/newsletter-05-2016.pdf" class="w-inline-block"> 
  
  May</a> 
  
  </div>
  
  ```
  
  **Tags:** craft3, archives
  
  > **Comments:**
  > **username_1**: can you edit with input/output?  
  > **username_0**: ok updated with output. Not seeing year and months are all grouped together instead of in separate years.  
  
  ---
  
  ## 0 answers
  
  