Building further on this problem, I try to make a loop that exits when the next opening hours or in other case events are found.

There is an event on all days except monday. I added a couple of extra elseif statements in case they drop a couple of events.

I have the following code (based on the answer below I changed my code)

{% for entry in craft.entries.section('events').level(2) %}
  {% if entry.dayOfEvent == now|date("l") %}
    {{ entry.dayOfEvent }}
  {% elseif entry.dayOfEvent == now|date_modify("+1 day")|date("l") %}
    {{ entry.dayOfEvent }}
  {% elseif entry.dayOfEvent == now|date_modify("+2 days")|date("l") %}
    {{ entry.dayOfEvent }}
  {% elseif entry.dayOfEvent == now|date_modify("+3 days")|date("l") %}
    {{ entry.dayOfEvent }}
  {% else %}
{% endfor %}

But this doesn't seem to do it. It's probably basic stuff, but what am i doing wrong?


Based on the answer below I changed my code

The output clearly gives me my days. But the {% elseif %} doesn't work, I just get the day outputted as well for all events in that range. Shouldn't it exit the loop as soon as the condition is met?

1 Answer 1


It's probably because entry.dayOfEvent isn't returning exactly what "now"|date_modify('+1 day') is returning therefore the comparison fails. Maybe one includes the time and the other doesn't, for example.

You can see what each is returning by doing:

{{ entry.dayOfEvent }}
{{ "now"|date_modify('+1 day') }}

If they are different formats, then you can make the 2nd one match the format of the first by using Twig's date format method.

  • thx for your input.. I updated the question in hope for further help.
    – eek-a-edge
    Commented Oct 1, 2014 at 12:11
  • What are the possible values for entry.dayOfEvent?
    – Brad Bell
    Commented Oct 1, 2014 at 16:46
  • I tried with day names and with the numbers 1-7 with the |date("N") format. The results are fine. If it's wednesday it show that day. If i switch it to numbers it show the number and the entries. It may work with this plugin i'm currently testing. But i get deleted entries returned. ex i created an event wednesday test that I deleted from the structure, but it still comes up in the results. It looks like the entry is still in the dB.
    – eek-a-edge
    Commented Oct 1, 2014 at 16:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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