On Fri, 2007-12-28 at 15:36 -0500, Ned Batchelder wrote:
> Just a matter of taste.  I suppose filtering in the view would be the
> simplest way to achieve what I'm looking for.
> 
> For my own edification: is there a way to write an iffirst tag?  I
> often wish for it.

In the tag code, test to see if context['forloop']['first'] is True or
not. That's the Python equivalent of {% if forloop.first %} in a
template.

But, seriously, use {% if forloop.first %}. It even works for nested
for-loops:

        {% for x1 in some_list %}
           {% for x2 in some_other_list %}
              {% if forloop.parentloop.first %}
                 x1 is still on it's first iteration.
              {% endif %}
           {% endfor %}
        {% endfor %}
        
"parentloop" always points to the parent loop or is {} when there's no
nesting above the current loop.

(And, yes, the wheels will come fall off if you ever create your own
context variable called "forloop", so don't do that.)
        
Regards,
Malcolm

-- 
Tolkien is hobbit-forming. 
http://www.pointy-stick.com/blog/


--~--~---------~--~----~------------~-------~--~----~
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