I appreciate the advice, but forloop.first won't work for what I'm trying to do. If the first thing chosen is in the second iteration of the for loop, then forloop.first is never true. I don't want to know if I'm on the first iteration of the loop. I want to know if it's the first time in the if clause:
{% for thing in mylist %} {% if thing.test %} {% iffirst %}Things: {% else %}, {% endiffirst %} {{thing}} {% endif %} {% endfor %} --Ned. Malcolm Tredinnick wrote: > 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 > > -- 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 -~----------~----~----~----~------~----~------~--~---