<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>

CC BY-SA 4.0
2018-06-07T17:49:47.403Z
can you edit with input/output?
Clark Nelson
CC BY-SA 4.0
2018-06-08T02:48:25.980Z
ok updated with output. Not seeing year and months are all grouped together instead of in separate years.
glider
<craft3><archives>
Creating an archive with linked asset
# 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") %}
      
        {{ year }}

        {% for month, entries in entriesInYear | group("postDate|date('F')" ) %}

            {% for entry in entries %}
                {% for asset in entry.file %}
                {% endfor %}
            {% endfor %} 

                {{ month }} 

        {% endfor %}

      
  {% endfor %}

This outputs:
    
        

                           

June 

                           

May

**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

