Skip to content
Grav 2.0 is officially stable. Read the announcement →
Archive

Page collection for future events

Started by Muut Archive 9 years ago · 4 replies · 421 views
9 years ago

Hi all,
Another question :) (I'm almost done with this project and now I'm tackling the last things I had a hard time with along the way). I have a page where I show events. All the pages in the collection have a start and end date. Now I would like to only display the events that are in the future. I saw that I can add dateRange to the frontmatter. Does this filter on the publication date of the page? And is there a way I can use dateRange to apply to my custom start and end date? Or is there another way to configure my page collection so that it only shows future events? Thanks a lot in advance!

9 years ago

The date: option in frontmatter is the only date that describes when a page is to be published. If you put a future date, the page is not 'published' until that date is past. This allows you to create posts/content and it will auto-publish in the future.

If you want to get all the pages in the future you will need to create your own collection and filter by date.

9 years ago

Thanks for your clear reply! I now replaced my custom date input event_end by the default date and added the following frontmatter to my event index page:

YAML
content:
    items: '@self.children'
    dateRange:
        start: today
        end: 1/1/2100

A weird thing happens now though; it only shows the event that is happening today, while it should display all events that are happening from today until January 1st 2100. What is going wrong?

9 years ago

I think it is due to the fact that dateRange is checking only for the publication date. Maybe someone can provide a solution, but I think you could achieve it with Twig with something like this:

TWIG
{% endfor %}

I didn't test it, so there might be some syntax error

9 years ago

@paul thanks for your reply! Along the way I found out that my yaml data was not rendered correctly. Threw out my event pages and started from scratch. Now the dateRange did work :)

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1333 9 years ago
Archive · by Muut Archive, 9 years ago
2 924 9 years ago
Archive · by Muut Archive, 9 years ago
2 4055 9 years ago
Archive · by Muut Archive, 9 years ago
1 2933 9 years ago
Archive · by Muut Archive, 9 years ago
3 1110 9 years ago