Forum Discussion

Marc's avatar
Marc
Active Member
2 years ago

Liquid using time of open conditions in email?

Can we use liquid in an email to display certain content based on time of email open? So, if a user opens an email during morning hours, have it serve X content. And if a user opens the same email du...
  • DavidO's avatar
    2 years ago

    Hi Marc 

    Liquid is evaluated at the time an email is sent, so any time-based calculations are evaluated when the email is triggered and already rendered before the email is delivered. Even if you recorded the email open click, the email is already rendered in their inbox, so I'm struggling to see how it could be updated in real-time but I would love to know if others have workarounds, it's a great question.

    For reference, some liquid that can determine the time of day would look something like the following:

     

    {% assign timeOfDay = 'now' | date: '%H' | plus: 0 %}
    
    {% if timeOfDay >= 0 and timeOfDay < 12 %}
      Good morning!
    {% else %}
      Good evening!
    {% endif %}

     

    This assigns the current time 'now' to a variable, only keeping the current two-digit hour (%H), for example 02. Since this returns a string, we plus a 0 to that string. which turns the 02 into an integer that we can work with.

    The if / else is then determining morning and evening based on that hour.

    I hope that helps😊