Previous events

Show Previous or past events

What is the best way to build a loop that shows only previous events. Any event from yesterday through to the first event, sorted reverse chronologically.

Feb 13, 2018
Feb 10, 2018
Feb 02, 2018
Jan 23, 2018
Dec 21, 2017
etc…

{{ $events := where .Site.RegularPages.ByDate "Section" "events" }}
{{ range where $events "Date" "ge" (now.AddDate -1 0 0) }}
  {{ .Render "past"}}
{{end}}

This is what I do:

{{ $events := .Data.Pages.ByDate }}
{{ $events_past := where $events.Reverse ".Date.Unix" "<" now.Unix }}

The example is on a event list template. In other templates, your .Site.RegularPages.ByDate "Section" "events" is correct and your (now.AddDate -1 0 0) looks correct

The “Unix” should be superfluous.

1 Like