New: Learn Statamic on Laracasts!

We've retired the forum in favor of GitHub Discussions.

New conversations can be started on GitHub. Existing conversations will remain for a while longer.

Head over to GitHub →

How to filter array by date and show only result

Alex Armstrong May 20, 2019 by Alex Armstrong

I'd like to filter the following array so that it only returns the next deadline:

important_dates:
  -
    important_date__date: '2019-03-20'
    important_date__label: 'Deadline 1'
  -
    important_date__date: '2019-06-02'
    important_date__label: 'Deadline 2'
  -
    important_date__date: '2019-09-08'
    important_date__label: 'Deadline 3'
  -
    important_date__date: '2019-11-03'
    important_date__label: 'Deadline 4'

In theory, I should filter it so that it only shows us to first ( limit="1") future item (is_future). But I can't figure out how to do this on an array.

I thought this would work, but it doesn't:

{{ important_dates sort="important_date__date" limit="1" is_future="important_date__date" }}
...
{{ /important_dates }}

Any other ideas?

Answered by Erin Dalzell!
>>>>>>> Answered <<<<<<<
5 Replies
3 Followers