Opened 16 years ago
Closed 16 years ago
#10821 closed (duplicate)
[patch] Add new template tag to test 'foo in bar'
Reported by: | tomevans222 | Owned by: | nobody |
---|---|---|---|
Component: | Template system | Version: | 1.0 |
Severity: | Keywords: | ||
Cc: | Triage Stage: | Unreviewed | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
There is currently no way for a template to test whether a value is in a list or not.
This is quite a useful tag to have, when drawing tables for example:
ctxt = { 'my_colours': ['orange', 'yellow'], 'all_colours': ['red', 'orange', 'yellow', 'green', blue', 'indigo', 'violet'] }
<tr>{% for clr in all_colours %}<th>{{ clr }}</th>{% endfor %}</tr> <tr> {% for clr in all_colours %} <td>{% IfInList clr in my_colours %}I like it{% else %}I hate it{% endif %}</td> {% endfor %} </tr>
Attached file adds functionality, but (as I need this now) it follows the style I use for my supplementary tag libraries (camel case node name, 2 space indents, standalone) so would need to be polished slightly to go in django/template/defaulttags.py
Attachments (1)
Change History (2)
by , 16 years ago
Attachment: | if_in_list_tag.py added |
---|
comment:1 by , 16 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
ifin
and ifnotin
already proposed by #8087.
Note:
See TracTickets
for help on using tickets.
Implementation of IfInList tag