Forum

Thread tagged as: Question

Date conditional template tag

Hey

My Perch is a bit rusty - we have a page with a date field (id course_date) and a payment link (id course_payment). How best to filter display of a payment button based on if link is present and date is greater than or equal to current date. Is it possible to concatenate multiple if queries into one conditional or would these have to be broken down into separate conditions.

Tried the latter but button still showing, even for items the date for which has expired.

For example, trying following:

<perch:if exists="course_payment">
    <perch:if id="course_date" value="{today}" match="gte">
    <dl>
        <dt class="paypal-dt"></dt>
        <dd class="paypal-dd"><a href="<perch:content id="course_payment" type="text" label="Course payment link" />">Pay and book</a></dd>
        </dl>
    </perch:if>
</perch:if>

Any suggestions appreciated.

Cole

Diagnostics:

Perch: 2.8.24, PHP: 7.0.12, MySQL: mysqlnd 5.0.12-dev - 20150407 - $Id: 241ae00989d1995ffcbbf63d579943635faf9972 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.24), assets (2.8.24), categories (2.8.24), perch_blog (4.6), perch_forms (1.8.3)
App runtimes: <?php $apps_list = array( 'content', 'categories', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Applications/__MAMP/htdocs/yoga/perch
PERCH_CORE: /Applications/__MAMP/htdocs/yoga/perch/core
PERCH_RESFILEPATH: /Applications/__MAMP/htdocs/yoga/perch/resources
Image manipulation: GD Imagick
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: dc1fef2ad0fcd9f943c02ebb43d85dbc
Resource folder writeable: Yes
HTTP_HOST: local.yogabodhi.co.uk
DOCUMENT_ROOT: /Applications/__MAMP/htdocs/yoga
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
Cole Henley

Cole Henley 0 points

  • 4 years ago

On a separate but related note - would I have to re-save affected entries for these template changes to come into effect?

Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you passing the current date into the template? If not, you'll need to do that:

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

and then make sure you're using perch_content_custom() to display the region, as you need it to be evaluated in real time, not used from cache.

perch_content_custom('Region name', []);

That worked - great, thanks!