In a Django template for loop, checking if current item different from previous item

Viewed 7830

I'm new to django and can't find a way to get this to work in django templates. The idea is to check if previous items first letter is equal with current ones, like so:

{% for item in items %}
    {% ifequal item.name[0] previous_item.name[0] %}
        {{ item.name[0] }}
    {% endifequal %}
    {{ item.name }}<br />
{% endforeach %}

Maybe i'm trying to do this in wrong way and somebody can point me in right direction.

1 Answers
Related