{% ifchanged %}

Typically called inside a {% for %} loop. Executes a block of code but only outputs the result if this is the first time it was called or if the previous call had a different result.

Syntax

{% ifchanged %}...{% endifchanged %}

The ifchanged tag creates a new child scope.

Examples

Ifchanged

Copy
Template: {% var list = "1,3,2,1,3,1,2" | split: "," | sort %} {% for item in list -%} {%- ifchanged %} {{ item }}{% endifchanged -%} {%- endfor %} Outputs: 1 2 3