1

I have set up a structure that allows me to display events with some information. I'd like to know if there's a way that I can set a date that will automatically change certain it's a text from being future tense to be in present tense during the event and past tense after the event i.e. I'll be, I am, I was.

Thanks to everyone in advance!

2

I guess you could do something like this. I'm assuming the events have eventStart and eventEnd date variables, and I'm here comparing the dates with the built in now variable on the format year-month-hour-minute:

{# When eventStart is bigger than "now", the event is in the future #}
{% if event.eventStart|date('YmdHi') > now|date('YmdHi') %}
  I will attend this event!

{# When eventStart is in the past, and eventEnd is in the future, the event is ongoing #}
{% elseif event.eventStart|date('YmdHi') <= now|date('YmdHi') and event.eventEnd|date('YmdHi') > now|date('YmdHi') %}
  I am at this event RIGHT NOW!

{# When none of the above, the event is in the past #}
{% else %}
  I was at this event
{% endif %}

Depending on your use, you could build on this to create a variable for "past/present/future" or similiar. To be even more sure on your validation, the last endif could also specifically test that the endDate is in the past, instead of just being a catch-all else.

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.