Sorting by a date param

I’m trying to list events by closest to furthest away with the following code:

{{ $events := (where .Site.RegularPages "Section" "evento") }}
{{ range $events.GroupByParamDate "eventdate" "2006-01-02" }} 

And I’m getting the error

 error calling GroupByParamDate: runtime error: index out of range [0] with length 0

Am I missing something?

The working code ended up being this:

{{ $events := (where .Site.RegularPages "Type" "evento") }}
	{{ range  $idx, $item := sort $events ".Params.eventdate" "asc" }}

And also the site I was working on didn’t have a standard datetime format and that was messing up the order.

1 Like