rhewitt
September 28, 2018, 1:31pm
1
I’m creating a content type of Events. Each event has a start
and end
page parameter. I haven’t been able to sort by that page parameter so I tried introducing the date
variable to try to sort by that without any luck. Can you help me reverse the order of my events for my list page?
Frontmatter
---
date: 2019-05-03T09:00:00.000Z
start: 2019-05-03T09:00:00.000Z
end: 2019-05-03T12:00:00.000Z
---
Template attempts
{{ $paginator := .Paginate (where .Data.Pages.ByDate.Reverse "Section" $section) 7 }}
{{ $paginator := .Paginate (where .Data.Pages "Section" $section).ByDate.Reverse 7 }}
{{ $paginator := .Paginate (sort (where .Data.Pages "Section" $section) "start" "asc") 7 }}
There are no errors in the terminal, and the order of the events never changed.
maiki
September 28, 2018, 2:54pm
2
Please read Requesting Help and share your project’s code, so other may assist.
zwbetz
September 28, 2018, 8:27pm
4
Tried cloning your repo but it’s over 7GB so that’s not an option for me.
Try removing .Data
(untested )
{{ $paginator := .Paginate (where .Pages.ByDate.Reverse "Section" $section) 7 }}
1 Like
bep
September 28, 2018, 8:46pm
5
That will be the same.
Most of the variants above all looks correct.
Give this a whirl:
{{ $pages := where .Data.Pages "Section" $section }}
{{ $sorted := $pages.ByParam "start" }}
reverse:
{{ $sorted := ($pages.ByParam "start").Reverse }}
{{ $paginator := .Paginate $sorted 7 }}
{{ $sorted := sort $pages "Params.start" "asc" }}
also seems to work.
1 Like
It turned out Hugo was rendering the page with a different template than I thought it was using…
Once that was straightened out I used @pointyfair suggestion with success.
{{ $pages := where .Site.Pages "Section" $section }}
{{ $paginator := .Paginate $pages 7 }}
ul.card-list
{{ range sort $paginator.Pages "Params.start" "asc" }}
{{ .Render "summary" }}
{{ end }}
{{ partial "pagination.html" . }}
bep
October 1, 2018, 1:08pm
8
You nees to sort them before you paginate them.
2 Likes
tubia
May 31, 2019, 10:11am
9
If I try to use this solution in _default/list.html
template I get undefined variable "$section"
.
Is there anything I am missing here?