Hi!
I’d like to implement a small year-based logic using Twig syntax.
When I use the following Twig syntax:
{{ ("first sunday of january " ~ y)|date("d.m.Y") }}
I get the date of the first Sunday in January. Since January has already passed this year, I’d like it to automatically return the date of the next first Sunday in January of the following year.
I found the following approach, which should handle this logic:
{% set y = ("now"|date("n") > 1) ? ("now"|date("Y") + 1) : ("now"|date("Y")) %}
{{ ("first sunday of january " ~ y)|date("d.m.Y") }}
However, when I insert this syntax into a Text Component, it doesn’t work and I only get an error message.
Is there a Twig expert here who could give me a few hints on what I might be doing wrong or how to best implement this?
Alternatively, the question is also directed at @Dan or @Ben, if you happen to have the time.
Thanks




