2

I'd like to get an output of Spring 2015 from a post entry that was written in March. Here is a JavaScript solution

http://jsfiddle.net/RtC58/3/

But I'm hoping I can do something in the template instead. Thanks!

1 Answer 1

5
{% switch entry.postDate|date('M') %}

    {% case 'Dec' or 'Jan' or 'Feb' %}
        {% set season = 'Winter' %}

    {% case 'Mar' or 'Apr' or 'May' %}
        {% set season = 'Spring' %}

    {% case 'Jun' or 'Jul' or 'Aug' %}
        {% set season = 'Summer' %}

    {% case 'Sep' or 'Oct' or 'Nov' %}
        {% set season = 'Fall' %}

{% endswitch %}

<p>{{ season }} {{ entry.postDate|date('Y') }}</p>
3
  • That is way simpler than what I would have tried. Thanks!
    – jasonetco
    Commented Mar 19, 2016 at 4:39
  • Wow. Didn't actually know you could have an or statement inside a {% case %} tag. +1, Lindsey! Commented Mar 20, 2016 at 8:50
  • 2
    @MatsMikkelRummelhoff: That's a brand new feature as of Craft 2.6!
    – Lindsey D
    Commented Mar 20, 2016 at 14:46

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.