Forum
Can you comparing a date inside a repeater?
I've got a repeater listing some course dates and want to hide a button the date is today or older...
Venue | Date | Price | Button
Venue | Date | Price | Button
In the page I've got...
PerchSystem::set_var('today', date('Y-m-d'));
perch_content_custom('Courses', [
'template'=>'courses_detail.html'
]);
Which brings in today
into the template. checked.
And the template repeater is using (with some test fields)...
<perch:repeater id="dates" label="Courses List" scope-parent="true">
<perch:before>
<h2>Course Dates:</h2>
<ul class="timetable"></perch:before>
<li class="timetableitem">
<perch:content id="parent.today" type="date" /> |
<span class="venue"><perch:content id="venue" type="text" label="Venue Name" size="l" help="Add the school name" /></span> |
<span class="location"><perch:content id="location" type="date" label="Venue Location" type="text" size="m" help="Add location e.g. Ilkley" /></span> |
<span class="date"><perch:content id="date" type="date" label="Course Date" format="%a %e %b %g" /></span> |
<perch:if not-exists="cost">
<span class="cost"><perch:content id="parent.cost" type="text" label="Course Price" size="s" help="Add the cost of this course in pounds" format="#:2" /></span>
<perch:else />
<span class="cost"><perch:content id="cost" type="text" label="Custom Price" size="s" help="Override the custom price set earlier - numerals only!" format="#:2" /></span>
| <perch:if id="date" match="gte" value="{today}" format="%a %e %b %g" > ... remove button ... </perch:if>
</perch:if>
</li>
<perch:after></ul></perch:after>
</perch:repeater>
Thing is I've tied a few different ways like to test <perch:if id="date" match="neq" value="{today}" format="%a %e %b %g" > ... remove button ... </perch:if>
and this should trigger ... remove button ...
if all dates are neq
but it only appears on the first repeat and not the second.
So I'm thinking before I go further, is this even possible in a repeater?
...just to add... date comparing outside of the repeater works OK.
... scrub this. Think I've found the problem. A line is incorrectly in a
<perch:if>
... checking...Mmm... fixed the repeating
perch:if
but I still cannot detect today's date inside the repeater to check against.Any pointers to where I'm going wrong?
I can get today's date inside using
<perch:content id="parent.today" type="date" format="%a %e %b %g" />
But that does not workHow do I get value="{today}" inside a repeater to check against?
...look like the issue was
format="%a %e %b %g"
. And by using simply<perch:if id="date" match="gte" value="{today}" >
is working. Looks like I was overthinking the problem.