---
title: Gallery
images:
- image:
description: An apple
imagefile: apple.jpg
- image:
description: Citrus fruit
imagefile: orange.jpg
- image:
description: Yellow and bent
imagefile: banana.jpg
---
I can iterate over this via {{ range .Params.images }}, which works fine.
Is there a way to reverse the order of the range as is possible for builtin ranges like .Pages?
Things like {{ range (.Params.images).Reverse }} do not work, presumably because these frontmatter-derived ranges aren’t the correct type for that method.
Introducing an extra key really feels like over-engineering in this case. The CMS cannot natively write indices, the order in the frontmatter is the order chosen by the user. Alas, I cannot easily reverse the order at the CMS level either.
Any other ideas welcome.
For now I may fall back on a hack like CSS flex-wrap: flex-reverse;
No need to add a new key. I meant use the existing description or imagefile.
I’m on my phone so cannot give you a code example at the moment.
But see the hugo docs on the sort function for examples.
{{ $slice := your list }}
{{ $len := len $slice }} <!-- get length of list -->
{{ range (seq $len) }} <!-- see docs -->
{{ $i := sub $len . }} <!-- $i at first iteration will be (len - 1), then (len - 2) etc -->
{{ index $slice $i }} <!-- get list element at $i -->
{{ end }}
Please tell me how can I get the value of imagefile in this particular case? I’m grabbing data from a data file with similar structure as given above. I’m getting a kind of map thing but not sure how to get the url out of the map. Please eleborate.