Reputation: 13860
I have forloop in my template and i use forloop.counter but in this case:
{% for item in items %}
{% if item.name %}
{{ forloop.counter }} - {{ item.name }}
{% endif %}
{% endfor %}
forloop failed. It shown:
1 - bla, bla
5 - woo, woo
...
How to count only visible items?
Upvotes: 1
Views: 511
Reputation: 16361
When confronted with this problem, I would pass a "list of visible items" to the template. If you need both lists on the page for some reason, then pass both lists to the template. One is just a filtered queryset of another.
Upvotes: 2