Section filters

It’s nice that section filters are coming to kirby 4!

I tried to filter pages by the current date with the help of a page method or page model. But it doesn’t seem to work.

query: site.childrenAndDrafts.filter('dateStart', '>=', '{{ }}')

It works perfectly with a string, f.ex.

query: site.childrenAndDrafts.filter('dateStart', '>=', '2023-09-28')

Are just static values allowed like in the example on the website, or is there something I missed?

Is that your model method?

Yes, is the model in this case. But I tried it also with a method.

The model looks like this:

class ExhibitionPage extends Page {
    public function now()
        return date('Y-m-d');

Both method or model works fine if I want to display it in the list item like info: '{{ }}'

To compare a date value, try using date >= as comparison operator

query: site.childrenAndDrafts.filter('dateStart', 'date >=', '{{ }}')

Sadly, it doesn’t work…

A workaround would possibly be a programmable blueprint, right?

Or should the way I tried work in theory?

I had the same issue today and could only fix it with a programmable blueprint. The comparison operator 'date >=' works like expected then.

Two things:

  1. You are passing the string '{{ }}' to the filter method. The whole line already is a query, there’s no further template “substitution” happening ('{{ }}' simply stays '{{ }}'). You would probably want to write this as

    query: site.childrenAndDrafts.filter('dateStart', 'date >=',
  2. if you just want to compare the date with “now”; it’s interesting to know that, in PHP, stuff like “now”, “today”, “tomorrow”, “Tuesday next week” or “first day of January this year” are actually all valid date strings. You wouldn’t therefore need a model function, it’s enough to write

    query: site.childrenAndDrafts.filter('dateStart', 'date >=', 'today')

    To have the same effect.


Thanks for the explanation. You are totally right!

Oh, nice! Didn’t try out today. That definitely works!