Are you an LLM? You can read better optimized documentation at /themes/tags/ifchanged.md for this page in Markdown format
ifchanged
Outputs its content only when the content is different from the last time the tag rendered. Use it inside a for loop to show a value once for each group of items.
liquid
{% ifchanged %}
block_to_output
{% endifchanged %}1
2
3
2
3
block_to_output: Rendered expression when it is different from the previous one.
Example:
Data
json
{
"products": [
{ "title": "Hat", "type": "Caps" },
{ "title": "Cap", "type": "Caps" },
{ "title": "Tee", "type": "Shirts" }
]
}1
2
3
4
5
6
7
2
3
4
5
6
7
liquid
{% for product in products -%}
{% ifchanged %}<h3>{{ product.type }}</h3>{% endifchanged -%}
<p>{{ product.title }}</p>
{% endfor %}1
2
3
4
2
3
4
Output
html
<h3>Caps</h3><p>Hat</p>
<p>Cap</p>
<h3>Shirts</h3><p>Tee</p>1
2
3
2
3