0

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.

Brooks Seymore
  • 306
  • 2
  • 13

2 Answers2

2

I'm not sure this solves your problem, but I think I spotted a typo in your code. In your example it says:

if g_show_date|is_future

Where I got a better result changing it to

if g_show_date|in_future

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)

David S
  • 21
  • 1
  • Good catch. I tinkered with this some earlier today but ran into one issue. Trying to work around it but if not, the client can just go in and tweak things manually. – Brooks Seymore Feb 02 '14 at 03:53
0

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.

{{ entries:listing folder="shows" limit="3" }}
  {{ show_time_grid limit="1" }}

    {{ if { g_show_date format="Ymd" } >= { current_date format="Ymd" } AND
          { g_show_time format="Hi"  } >  { current_date format="Hi"  }
    }}  
      {{ g_show_date }}<br/>
      <h2>{{ title }}</h2>
    {{ endif }}

  {{ /show_time_grid }}
{{ /entries:listing }}

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.

Curtis Blackwell
  • 3,130
  • 3
  • 27
  • 45
  • Doesn't `show_past="false"` just keep older entries from being pulled up? My edited question above (Example Show Data) has grid content in an older entry so show_past just prevents that entry from showing up. What I'm trying to do is filter out past dates from within grid data stored in that older entry. I *think* the next major release will let me do this. Logically, your original suggestion should work, same with `{{ g_show_date|in_future }}` but (so far) not having luck with that. – Brooks Seymore Feb 02 '14 at 04:09
  • Ah, you're right. I forgot it was an older entry. I rolled back. I'm not sure why that doesn't work. I would try throwing this on the official forums and including the different versions you tried. Unfortunately, I don't know what else to suggest other than tinkering with things until it works, or revisiting your setup. – Curtis Blackwell Feb 02 '14 at 05:03
  • For now, I'm going to pivot and either have the client manually delete past performances from the grid (no need to keep them) or tinker with the publish date of the entry so I can use the `show_past` and `show_future` parameters — appreciate the help! – Brooks Seymore Feb 02 '14 at 06:45