hi
While trying out lessons on templates.I tried using the variables in
'for' to print the names of 2 tags in a list called taglist.(template
code is given at the bottom)
I could n't understand why ifequal forloop.revcounter0 1 is used
instead of revcounter..
I tried to follow the logic using revcounter variable,
1st iteration of for:
print tagname of first tag
current iteration is not the last
check if 1 iteration is left ,revcounter should return 1 since 1
more iter is left,so should print the word 'and'
2nd iteration:
print tagname of second tag
forloop.last is true,nothing printed
forloop ends
According to above logic I should be getting the result as
firsttag and secondtag
Still ,I got the correct result only when i used ifequal
forloop.revcounter0 1
Can someone tell me how I got the logic wrong..I am quite confused
thanks
harry
{% load tagging_tags %}
{% tags_for_object object as taglist %}
{% if taglist.count %}
{{ taglist.count}} Tags for this link are :
{% for tag in taglist %}
{{tag.name}}
{% if forloop.last %} {% else %}
{% ifequal forloop.revcounter 1 %} and {% else %},{% endifequal %}
{% endif %}
{% endfor %}
{% else %}
No tags for this link
{% endif %}
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en.