Shopify 08/17/2006

New liquid tag: ifchanged

While designing this blog Daniel wanted to display dates only if they actually changed since the last time.

We quickly came to realize that this is a great reusable pattern and we wanted to dedicate some first class support to this kind in liquid.

Ifchanged does exactly this. The block contained within ifchanged will only be rendered to the output if the last call to ifchanged returned different output.

Here is an example:

  <h1>Product Listing</h1>
  {% for product in products %}
    {% ifchanged %}<h3>{{ product.created_at | date:"%w" }}</h3>{% endifchanged %}
    <p>{{ product.title }} </p>
     ...
  {% endfor %}