From 9ea33f0dbdf25a5d9a4c34326f4c29dde5711365 Mon Sep 17 00:00:00 2001 From: Koen Bolhuis Date: Wed, 8 Feb 2023 22:31:18 +0100 Subject: [PATCH] Fix erroring suggestion in docs (#2087) The docs suggest `reverse` after `group_by`, but that causes an error. --- docs/content/documentation/templates/archive.md | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/docs/content/documentation/templates/archive.md b/docs/content/documentation/templates/archive.md index 467d12c6e3..efccfe7150 100644 --- a/docs/content/documentation/templates/archive.md +++ b/docs/content/documentation/templates/archive.md @@ -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 %} +```