1

I currently have an empty date field, it's unset in the field. I know from reading this becomes "Today's Date" but for some reason the following code is just not working when testing for empty? Unsure why this is?

{% if entry.eventStartDate is not empty %}

  {% elseif entry.eventStartDate > now %}
    There is a date and it's greater than now.

  {% elseif entry.eventStartDate < now %}
    There is a date and it's before now.

  {% else %}
    There is no date set.
{% endif %}
  • What's the output of {{ dump(entry.eventStartDate) }}? – Paul Mar 6 at 13:40
2

An empty date field will return null. Your conditional is slightly off as you have an elseif straight after your first if. Try:

{% if entry.eventStartDate is empty %}
    There is no date set.
{% elseif entry.eventStartDate > now %}
    There is a date and it's greater than now.
{% elseif entry.eventStartDate < now %}
    There is a date and it's before now.
{% endif %}
| improve this answer | |
  • 1
    Absolutely bang on. – JMKelley Mar 6 at 15:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.