On a Statamic 1.6.7 based site for a theater I want to use a grid field for performances (they have shows which every Saturday night for several weeks ) and I want to show only the next upcoming show.
EXAMPLE SHOW DATA:
show_performances:
-
g_show_date: 2014-01-30
g_show_time: 07:00 PM
-
g_show_date: 2014-02-31
g_show_time: 07:00 PM
-
g_show_date: 2014-03-31
g_show_time: 07:00 PM
UPDATE No. 1 (1 February 2014)
And here is my code, where I'm trying David S's suggestion to use {{ g_show_date|in_future }}
:
{{ show_performances }}
{{ if g_show_date|in_future }}
<p>{{ g_show_date }} @ {{ g_show_time }}</p>
{{ endif }}
{{ /show_performances }}
Which works fine but it shows all future shows (both 2014-02-31 and 2014-03-31). I tried wrapping the output in an {{ if first }}
conditional which — as expected — still listed subsequent performances.
Any thoughts on how I can limit output to just the next performance, not any subsequent?
UPDATE No. 2 (1 February 2014)
I also tried Curtis' suggestion:
{{ show_performances limit="1" }}
{{if "{ g_show_date format='Ymd' }" >= "{ current_date format='Ymd' }"
AND "{ g_show_time format='Hi' }" > "{ current_date format='Hi'}"}}
<p>{{ g_show_date }} @ {{ g_show_time }}</p>
{{ endif }}
{{ /show_performances }}
but the {{ current_date }}
conditional seems to fails: as past performances are returned.
I'm not sure this solves your problem, but I think I spotted a typo in your code. In your example it says:
Where I got a better result changing it to
To have your code show only one next upcoming occurrence of each show I guess you would cycle through your loop with the next show as a condition. (not sure how to accomplish that one right now though)