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

Dates in page.collection()

Started by Muut Archive 11 years ago · 4 replies · 336 views
11 years ago

Is it possible already in Grav core to generate a collection using something like pull all posts after 01/01/2015?

11 years ago

Currently no, but as it happens i'm working on some collection refactoring today, so i'll take a look and see if this is easily doable.

11 years ago

Ok, I've added this and it will be in the next release which will be out very shortly.

Basically you can use it two ways. You can add a dateRange to a collection definition in the page headers:

YAML
content:
    items: @self.children
    order:
        by: date
        dir: desc
    limit: 5
    pagination: true
    dateRange:
        start: 1/1/2014
//        end: 1/1/2015

End date is optional and is commented out here. Also you can use 'human readable dates that are supported by PHP's strtotime(). So you could set a date to be something like start: "-6 months" to filter the pages for last 6 months only.

The other option is to act directly on the collection using similar syntax. For example:

TWIG
{% for p in page.find('/blog').children.dateRange('01/01/2014', '01/01/2015').order('date', 'desc') %}

As you can see this is pretty powerful, but I've also added modular(), nonModular(), nonVisible(), nonRoutable() and also published(), nonPublished() methods to Collection object. All of these are chainable, so you can really get some sophisticated results now.

Just need to document all these cool methods that will be available in Grav v0.9.13 :)

11 years ago

I think this is exactly what is needed to do events sort of stuff in Grav.

Suggested topics

Topic Participants Replies Views Activity
Archive · by Deleted User, 9 years ago
0 1318 9 years ago
Archive · by Muut Archive, 9 years ago
2 915 9 years ago
Archive · by Muut Archive, 9 years ago
2 4044 9 years ago
Archive · by Muut Archive, 9 years ago
1 2920 9 years ago
Archive · by Muut Archive, 9 years ago
3 1104 9 years ago