Forum

Thread tagged as: Question

Display message when using custom match / value / eq for date

Struggling to display a message when a date matches today's date. I have done this before but I can't get it to work for some reason this time round. I am using a repeater in the template this time.

Main template:

<perch:before>
        <div class="tab-pane" id="dates">
      </perch:before>

      <h3>Closure Dates</h3>

      <perch:content id="ClosureIntro" type="textarea" html="true" editor="ckeditor" label="Intro to Closure Dates"  />
      <dl class="dl-horizontal">
      <perch:repeater id="dateList" label="Dates">
        <dt><perch:content id="ClosureDate" type="date" label="Date of closure" format="d F Y" /></dt>
        <perch:if exists="ClosureDetails">
          <dd><perch:content id="ClosureDetails" type="text" label="Information?" size="xl"  /></dd>
        <perch:else />
          <dd>Closure order in force on this date</dd>
        </perch:if>
      </perch:repeater>
      </dl>
      <perch:after>
        </div>
      </perch:after>

For testing the message I am just using some basic HTML:

<div class="alert alert-danger">
          <p>Testing - Closure order in force on this date</p>
        </div>

In my page the structure looks like this:

Main region:

<!--Closure Dates (main template assigned to this region)-->
<?php perch_content('Closure Dates'); ?>

Sample to display message:

$opts = array(
          'page'=>'/about/open-access.php',
          'template'=>'_closureWarning.html',
          'filter'=>'ClosureDate',
          'match'=> 'eq',
          'value'=> date('Y-m-d'),
          );
        perch_content_custom('Closure Dates', $opts); 

I have tried filtering the repeater ID ('dateList') and the ID 'ClosureDate' but no real success. I tried 'contains' => date('Y-m-d') but this just displayed the message all the time.

All I'm trying to do is search the region 'Closure Dates' for the dates. If a date entered is the same as today's date then a message should be displayed.

What am I doing wrong or missing here?

Ben Stillwell

Ben Stillwell 1 points

  • 7 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

Are you trying to filter on the item within the repeater?

Try dateList.ClosureDate

Ben Stillwell

Ben Stillwell 1 points
Registered Developer

I created a template without a repeater region and it works fine:

<perch:before>
        <div class="tab-pane" id="dates">
        <h3>Closure Dates</h3>
        <dl class="dl-horizontal">
      </perch:before>

        <dt><perch:content id="ClosureDate" type="date" label="Date of closure" format="d F Y" /></dt>
        <perch:if exists="ClosureDetails">
          <dd><perch:content id="ClosureDetails" type="text" label="Information?" size="xl"  /></dd>
        <perch:else />
          <dd>Closure order in force on this date</dd>
        </perch:if>

      <perch:after>
        </dl>
        </div>
      </perch:after>

I would prefer to use a repeater in the template if possible, so I guess I would like to know if it is possible to filter a value (date in this case) from within a repeater?

Ben Stillwell

Ben Stillwell 1 points
Registered Developer

Thanks, Drew. That has worked a treat!

So for anyone else trying to filter content from within a repeater you just need to use {THE-REPEATER-ID}.{ID-TO-FILTER}. So in my case:

$opts = array(
          'page'=>'/about/open-access.php',
          'template'=>'_closureWarning.html',
          'filter'=>'dateList.ClosureDate',
          'match'=> 'eq',
          'value'=> date('Y-m-d'),
          );
        perch_content_custom('Closure Dates', $opts);