On Mon, 2009-10-26 at 15:54 +0200, Jani Tiainen wrote:
> NMarcu kirjoitti:
> > Hello all,
> > 
> >    I want to do something like this:
> > 
> >     {% for u in users %}
> >         {% for su in superu %}
> >             {% ifequal u su %}
> >                                            //do something end exit
> > from this for
> >             {% endifequal %}
> >         {% endfor %}
> >     {% endfor %}
> > 
> > How can I do this?
> 
> You can't and shouldn't. It's template language, not progamming 
> language. It's function to define _how_ to show data.
> 
> You need to make that decision in a view which is meant for extracting 
> and preparing _what_ to show.
> 

Now that someone has got the "you shouldn't do that" speech out the way,
here's how you can actually achieve it. Install the 'smart if' tag[1]
from djangosnippets, and alter your template code like so:

{% for u in users %}
  {% if u in superu %}
    {{ some_content }}
  {% endif %}
{% endfor %}

The smart if tag is allegedly slated for inclusion in django 1.2.

Cheers

Tom

[1] http://www.djangosnippets.org/snippets/1350/



--~--~---------~--~----~------------~-------~--~----~
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 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to