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.
You can use
{{ current_date }}and the format parameter to test if the time has passed yet.You might need to play around with the number of curly braces within the if tag; Tags are supposed to use single curly braces within other tags, but I've found it doesn't always work that way. I think someone (Gareth, maybe?) said they noticed it was native Statamic variables use single curlies, while custom variables use double.
The time format is using leading zeroes for months, days, and hours. Hours are 24-hour time so it doesn't behave unexpectedly with pre/post-noon showtimes. See the PHP manual for more information.