Forum

Thread tagged as: Question, Runway

Collections if past/if future

Here's my template for a collection of events:

<h1><perch:content id="event_name" type="text" label="Event title" required="true" title="true" /></h1>

<perch:template path="content/header_image.html" />

<p class="date"><perch:content id="date" type="date" label="Start Date" format="%d %B %Y" time="true" required="true" time="true"  divider-before="Date" /></p>
<p class="date"><perch:content id="end_date" type="date" label="End Date" format="%d %B %Y" time="true" time="true"  /></p>

<address>
    <perch:content id="venue_address1" type="text" label="Address 1" divider-before="Address" />
    <perch:content id="venue_address2" type="text" label="Address 2" />
    <perch:content id="venue_city" type="text" label="City" default="London" />
    <perch:content id="venue_postcode" type="text" label="Postcode" />
</address>

<perch:content id="event_map" type="map" label="Event map" width="400" height="300" zoom="15" />

<perch:if id="end_date" value="now" match="lt" format="U">
    <!--* Before the event *-->
    <perch:blocks divider-before="Event description" notes-before="This shows up BEFORE the event. You can add images, dividers, videos etc">
        <perch:template path="content/_blocks.html" />
    </perch:blocks>

    <perch:content id="embed" type="textarea" label="Embed code" editor="ace" markdown="false" html="true" help="Paste the booking widget from eg. Eventbrite here." divider-before="Embed code" />
<perch:else />
    <!--* After the event *-->
    <strong>This event has happened</strong>

    <perch:blocks divider-before="Post event info" notes-before="This shows up AFTER the event. You can add images, dividers, videos etc">
        <perch:template path="content/_blocks.html" />
    </perch:blocks>
</perch:if>

<perch:related id="related_conversations" collection="Conversations" label="Related Conversations">
    <perch:content id="parish_name" title="true"  />    
</perch:related>

Couple of issues. Firstly, what's the best way to make the "date" conditional work? I need to be able to check if an event has finished or not, and display something different if it has.

Here's what I have <perch:if id="end_date" value="now" match="lt" format="U">. How can I specify the value of "now"? Can I pass in a variable somehow when I call this with perch_collection(). (Obviously this wouldn't work with perch_content() in scenarios, as it needs to be run dynamically to determine when "now" is.

Related - what's the best way to filter for future/past events in perch_collection()?

Secondly, the template above has two <perch:blocks tags. Am I only allowed one per content region? Only one of them is showing up in the editor,

Paul Bell

Paul Bell 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

How can I specify the value of "now"?

On your page:

PerchSystem::set_var('now', date('Y-m-d H:i:s'));

In your template:

<perch:if id="end_date" value="{now}" match="lt" format="U">

what's the best way to filter for future/past events in perch_collection()?

perch_collection('Events', [
    'filter' => 'date',
    'match' => 'gte', 
    'value' => date('Y-m-d H:i:s'),
]);

the template above has two <perch:blocks tags. Am I only allowed one per content region?

That's right - just one set of blocks per item.

Thanks, Drew - I'll give that a try.

In my template, is format="U" correct? That's obviously not going to be the same format as the "now" variable?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You shouldn't need the format attribute here, actually.