Reputation: 4237
Say I have a tuple :
a = (1, 2, 3)
Now I want to do something like :
for i in a:
if i == 1:
print a[1]
I mean if the first element is 1 I want to immediately extract the second element without going into another iteration of the for loop.
How may I do this in a django template?
Upvotes: 0
Views: 129
Reputation: 17052
This does effectively the same thing as your Python code, assuming that you've passed a
to the template context:
{% for i in a %}
{% if i == 1 %}
{{ a.1 }}
{% endif %}
{% endfor %}
Upvotes: 2
Reputation: 13158
{% for i in a %}{% ifequal i 1 %}{{ a.1 }}{% endifequal %}{% endfor %}
Upvotes: 0