events app question - display date sensitive detail

  • Hi, using events app archive display - user has list of 'upcoming' and 'past' events. Is it possible that the event detail showing for an event can be different for a 'past' event than that showing when 'upcoming'?


    I ask because we may have an 'upcoming' race event - shows entry details etc. When race is 'past' we would like to show results, not entry details.


    I am guessing this could be done with some clever editing of the event-detail.html template to filter the upcoming and past descriptions


    Any ideas gratefully received, thanks.


    <div class="vevent">

    <h2 class="summary"><perch:events id="eventTitle" /></h2>


    <p class="dtstart"><span class="value-title" title="<perch:events id="eventDateTime" format="l, jS F Y g:i a" />"><perch:events id="eventDateTime" format="%c" /></span></p>


    <div class="description"><perch:events id="eventFutureDescHTML" type="textarea" editor="redactor" encode="false" /></div>


    <div class="description"><perch:events id="eventPastDescHTML" type="textarea" editor="redactor" encode="false" /></div>


    <p class="category"><perch:events id="category_names" encode="false" /></p>


    <perch:if exists="image">

    <img src="<perch:events id="image" type="image" label="Image" width="640" crop="true" />" alt="<perch:events id="eventTitle" />" />

    </perch:if>


    </div>

  • Something like this should work, where today is a passed in data variable. Using U for the format will convert them to Seconds since the Unix Epoch for a better comparison.

    Code
    1. <perch:if id="eventDateTime" match="lt" value="{today}" format-both="U">
    2.     <perch:template path="events/past">
    3. <perch:else/>
    4. <perch:template path="events/future">
    5. </perc:if>
  • Thanks Byron, that looks nice and effective. Where would I use that? In the archive.php page? or somewhere else


    <h2>Past events</h2>


    <?php

    perch_events_custom(array(

    'category' => perch_get('cat'),

    'filter' => 'eventDateTime',

    'match' => 'lt',

    'value' => date('Y-m-d'),

    'sort' => 'eventDateTime',

    'sort-order' => 'desc',

    'template' => 'listing/custom-listing-day.html'

    ));

    ?>

  • Ah sorry I misread the question, thought it was for single event pages not the archive. You'll probably want to make to perch_events_custom calls, one for future events and one for past events. Then just swap the templates you are using.

    If you want to combine it all together in one perch_event_custom call you can use my previous code in the listing/custom-listing-day file like follows. Where the future template shows your current template and your future template will show the results

  • So the above will show listing of events sorted by future and past


    For an individual event, how to filter to display future or past content?


    current event page


    <?php

    perch_events_custom(array(

    'filter'=>'eventSlug',

    'match'=>'eq',

    'value'=>perch_get('s'),

    'template'=>'listing/event-detail.html'

    ));

    ?>

  • Your event detail html template should look something like this

    Then your detail php page should look something like this

    PHP
    1. <?php
    2. // Sets a global variable today so we can use in the perch template
    3. PerchSystem::set_var('today', date('Y-m-d'));
    4. perch_events_custom([
    5. 'filter'=>'eventSlug',
    6. 'match'=>'eq',
    7. 'value'=>perch_get('s'),
    8. 'template'=>'listing/event-detail.html'
    9. ]);
  • Hi Byron, sorry to keep plundering your brain! last question, honest. So I can get to do most what i need but as the event.php is the only page that actually can display an event detail (because all events in a list point to the single "eventURL" as defined in settings for events) I need something in event.php that uses template event-detail.html for future events and template event-result.html for past events


    so in event.php we currently have


    <?php


    perch_events_custom(array(

    'filter'=>'eventSlug',

    'match'=>'eq',

    'value'=>perch_get('s'),

    'template'=>'listing/event-detail.html'

    ));

    ?>


    is there a conditional statement that can go in there to make the selction of templates? thanks for your help as always!

  • There is no easy way to set a conditional in that manner. You could use skip-template => true then check the date of the returned event and then user perch_template() to output the right template, though you'll need to use the perch:content namespace if you approach this way. So you might do something like this.



    It would be easier and cleaner to use perch:if tags in the template to then include either layouts or templates to get the desired result, like in my previous examples.

    Code
    1. <perch:if id="eventDateTime" match="lt" value="{today}" format-both="U">
    2. <perch:template path="events/past-detail">
    3. <perch:else/>
    4. <perch:template path="events/future-detail">
    5. </perc:if>


    Lastly you could run two queries, using a date filter as well. This works as the template is not shown if no event is found. I wouldn't recommend this though as you are making two calls to the database instead of one.