I'm making a list of objects, and only including some of them in the output:

    {% for thing in mylist %}
       {% if thing.test %}
          {{thing}}
       {% endif %}
    {% endfor %}

Now if I want to comma-separate the list, how do I do it?  The natural 
thing to my mind is an "iffirst" tag:

    {% for thing in mylist %}
       {% if thing.test %}
          {% iffirst %}Things: {% else %}, {% endiffirst %}
          {{thing}}
       {% endif %}
    {% endfor %}

{% iffirst %} is true the first time it is evaluated in each loop.  
Because of the "if thing.test", it could be evaluated first on the third 
time through the loop, for example.  That's why forloop.first isn't 
sufficient.

I've tried creating such a tag, but can't find the contextual 
information I need to know when the for loop has been restarted.

(Also: the whitespace will be messed up even if I do have this tag: the 
comma will have space before it).

So, two questions: 1) How would I create a tag like this, and 2) is 
there some simpler way to achieve my purpose?

--Ned.

-- 
Ned Batchelder, http://nedbatchelder.com

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to