Liquid logic to change what displays depending on time

Viewed 36

I'm trying to figure out how to send a specific message when the time is before or after a certain time.

I have a weekly recurring event (midday every Monday) and although I can vary messaging depending on the day of the week, I can't figure out how to go more granular and send different messaging depending on whether the current time is before or after midday on a certain day.

I'm struggling to find an answer because most logic is in relation to one single event (with a date and a time) whereas mine just needs to be in relation to a specific time that repeats once a week.

This is what I started off with:


{% assign today = 'now' | date: "%A" %}

{% assign time = 'now' | time_zone: ${time_zone} %}

{% case ‘today' %}

{% when 'Monday' %}

{% if hour < 12:00%}

Today's the big day!

{% if hour > 12:00%}

You have till next Monday

{% else %}

Default copy

{% endcase %}


But I'm definitely very far off, so I would love any help!

Thank you!

1 Answers

You're example is almost correct. You're missing some "endif" thus I suggest you to use some liquid aware IDE. I made an example that I hope it's clear enough you can adapt to your situation.

{% assign time = 'now' | time_zone: 'UTC' %}
{% assign today = time | date: "%A" %}
{% assign hour = time | date: "%H" %}
{% assign minute = time | date: "%M" %}


{% case today %}

    {% when 'Monday' %}

        {% if hour < "12" %}
            It's Monday Morning!
            {% if hour == "10" %}
                {% if minute > "20" %}
                    It's between 10:20 and 10:59
                {% endif %}
            {% endif %}

        {% else %}
            It's Monday Afternoon!
        {% endif %}


    {% when 'Tuesday' %}

        It's Tuesday

    {% when 'Saturday' %}
    {% when 'Sunday' %}

        {% if hour < "12" %}
            It's the weekend in the morning!
        {% endif %}

    {% else %}

        {% if hour < "12" %}
            It's another day in the morning
        {% else %}
            It's another day in the afternoon
        {% endif %}

{% endcase %}
Related