New liquid tag: ifchanged

Tobias Lutke

2

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 %}

Comments

John W. Long

John W. Long August 17, 2006 03:26PM EDT

Wow. I added something just like this to Radiant a while back. I called it though. If changed is a much better name.

Petr Vytlacil

Petr Vytlacil August 17, 2006 03:26PM EDT

Hi is anything as liquid for PHP? I know SMARTY, and other Template system. But liquid is very interesting for me. And you use liquid in project myshopify? THX Bye

Leave a Comment

Your email address will not be published.