Skip to content

Commit

Permalink
Fix erroring suggestion in docs (#2087)
Browse files Browse the repository at this point in the history
The docs suggest `reverse` after `group_by`, but that causes an error.
  • Loading branch information
InputUsername authored Feb 8, 2023
1 parent 3af1815 commit 9ea33f0
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions docs/content/documentation/templates/archive.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,16 @@ all post titles ordered by year). However, this can be accomplished directly in
```

This snippet assumes that posts are sorted by date and that you want to display the archive
in descending order. If you want to show articles in ascending order, add a `reverse` filter
after `group_by`.
in descending order. If you want to show articles in ascending order, you need to further
process the list of pages:
```jinja2
{% set posts_by_year = section.pages | group_by(attribute="year") %}
{% set_global years = [] %}
{% for year, ignored in posts_by_year %}
{% set_global years = years | concat(with=year) %}
{% endfor %}
{% for year in years | reverse %}
{% set posts = posts_by_year[year] %}
{# (same as the previous snippet) #}
{% endfor %}
```

0 comments on commit 9ea33f0

Please sign in to comment.