Forum

Thread tagged as: Problem

using perch:if with date tag

I can't seem to get this to work, even if I remove the date format (it defaults to current date so thought that might be the issue).

Darren Cusdin

Darren Cusdin 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

What are you trying?

 <perch:if exists="date">
          <perch:content id="date" type="date" label="Course date" format="%d/%m/%Y" order="3" />
          <br/>
        </perch:if>
Drew McLellan

Drew McLellan 2638 points
Perch Support

Ok, that looks fine. In what way is it failing?

The date still shows on the front-end, I want to be able to control that as not all entries have a date associated.

Drew McLellan

Drew McLellan 2638 points
Perch Support

type="date" will always have a value, won't it? How would you submit the form without it having a value?

Here's what I need to achieve, not sure it's doable!

Basically my template is for educational courses, some of which have course dates and some are TBA.

In the event that there is no associated date, I just need to hide the default date (today) and show TBA or nothing at all.

I know that this can usually be done with <perch:if> and else, but this functionality doesn't seem to work with the date tag.

Do you think this is achievable?

In short, is there a way to make adding a date optional?

You could do a checkbox for TBA

<perch:content type="checkbox" id="tba" value="1" label="TBA" suppress="true" />

And do a field for the date, and then do your perch:if

<perch:if exists="tba">
        ...COURSE DATE IS TBA...
<perch:else />
        ...<perch:content id="date" type="date" label="Course date" format="%d/%m/%Y" order="3" />...
</perch:if>

Then when you have the date, the content editor can uncheck tba and set the correct date.

Dexter! That worked a treat. Thanks for the contribution :)

Glad it helped :)