confused00
confused00

Reputation: 2612

Django template divisible by list length

I'm trying to use Django's template language to do some calculations:

{%  if forloop.counter|divisibleby:table.1|length %}

but I want the divisibleby to take table.1|length as an argument rather than only table.1 like it seems to do by default. (table.1 is a list)

Any way to do this besides passing the length from a view?

Upvotes: 0

Views: 1316

Answers (1)

schillingt
schillingt

Reputation: 13731

You could do something like using the template tag with

{% with table_length=table.1|length %}
    {%  if forloop.counter|divisibleby:table_length %}
    {% endif %}
{% endwith %}

Upvotes: 2

Related Questions