ifequal not working?

52 views
Skip to first unread message

Eloff

unread,
Jul 28, 2007, 2:42:43 AM7/28/07
to Django users
Thinking myself clever I added enumerate as a filter and did:

{% for i, item in menu_items|enumerate %}
{% ifequal i|add:1 menu_items:length %} class="last-item"{% endifequal
%}

To me I expect it to be true only for the last item, I printed {i|add:
1} and it works as expected. However, what happens is it's always
true. I don't understand it, does someone know why this is?

Thanks,
-Dan

Nathan Ostgard

unread,
Jul 28, 2007, 3:53:06 AM7/28/07
to Django users
ifequal can't do filters, unfortunately.

But you can do this:

{% for item in menu_items %}
{% if forloop.last%} class="last-item"{% endif %}
{% endfor %}

Or

class="{{ forloop.first|yesno:"first," }} {{ forloop.last|
yesno:"last," }}"

Reply all
Reply to author
Forward
Message has been deleted
Message has been deleted
0 new messages