I have posts in various directories. I want to focus my top page on posts in my /events
directory. The frontmatter of each “event” post includes eventDate
.
I want to show upcoming events separately from old events. I was able to make (theme)/events/list.html show events the way I want.
I want this list of events to be my top page, so I put “events” in mainSections
of my config.toml
, but have not figured out how to get (theme)/list.html to both filter on mainSection AND on frontmatter.
I have a test repo here GitHub - thunderrabbit/bfr-evention: how to use frontmatter to filter pages in mainSection?
I found Group And Filter Site mainSections but cannot understand how to apply it to my situation.
How can I show only upcoming events on my top page?
The simplest approach:
{{ range where (where .Site.RegularPages "Type" "events") "Params.eventDate" "ge" now }}
1 Like
TLDR: solution at bottom of this reply
Thank you for your quick reply. I have tried your suggestion as the following, but it gives an empty page:
{{ $future_events := where (where .Site.RegularPages "Type" "events") "Params.eventDate" "ge" now }}
{{ range sort $future_events "Params.eventdate" "desc" }}
If I remove the outer where
the page shows events, but also includes events that are older than now.
{{ $future_events := (where .Site.RegularPages "Type" "events") }}
{{ range sort $future_events "Params.eventdate" "desc" }}
I tried replacing now
with (now.Format "2006-01-02")
, which works on my events.html
template, but it shows an empty page.
{{ $future_events := where (where .Site.RegularPages "Type" "events") ".Params.EventDate" "ge" (now.Format "2006-01-02") }}
{{ range sort $future_events "Params.eventdate" "desc" }}
Oh wow this works! It looks like the main difference from your code is lowercase eventdate
{{ $future_events := where (where .Site.RegularPages "Type" "events") ".Params.eventdate" "ge" (now.Format "2006-01-02") }}
{{ range sort $future_events "Params.eventdate" "desc" }}
Please edit your reply to use lowercase eventdate and I will mark it accepted.
No. With v0.83.0 and later the key is case insensitive.