Using Liquid for Bi-Weekly Content Changes

  • 10 October 2023
  • 0 replies


Automating content delivery is an integral part of marketing campaigns. One use case that some users might encounter is the need to alternate between two different subject lines and/or email content on a weekly basis. This tutorial will guide you through setting this up in using a Liquid filter.



The use case concerns alternating between two different subject lines and content text on a weekly basis. The specific requirement is to display the first subject line and content on the 1st, 3rd, and 5th week and the second subject line and content on the 2nd, 4th, and 6th week.



There are two ways this could be achieved. The first involves converting the day into a numerical value and comparing the value against specific days of the month. In this example, we are using Liquid to display the content based on the date (i.e., 1st-7th is week one, 8th-14th is week two, etc.):

{% assign day = 'now' | date: '%d' | plus: 0 %}

{% if day >= 1 and day <= 7 or day >= 15 and day <= 21 or day >= 29 %}
Display content A
{% else %}
Display content B
{% endif %}


Alternatively, we could assign each week of the year as 'odd' or 'even' to display different content every other week. This requires assigning a numerical value to the current week of the year and using a modulo filter to find the remainder of the value when divided. If the number doesn't have a remainder, we can consider it to be even and display "Content A"; otherwise, if the number is odd, we can display "Content B". For instance:

{% assign week_number = 'now' | date: '%W' | plus: 0 %}

{% assign week = week_number | modulo: 2 %}

{% if week == 0 %}
Content A
{% else %}
Content B
{% endif %}



0 replies

Be the first to reply!