Opened 8 years ago

Closed 8 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: UI/UX:


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>
   {% for clr in all_colours %}
   <td>{% IfInList clr in my_colours %}I like it{% else %}I hate it{% endif %}</td>
   {% endfor %}

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/

Attachments (1) (2.8 KB) - added by tomevans222 8 years ago.
Implementation of IfInList tag

Download all attachments as: .zip

Change History (2)

Changed 8 years ago by tomevans222

Attachment: added

Implementation of IfInList tag

comment:1 Changed 8 years ago by Karen Tracey

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
Resolution: duplicate
Status: newclosed

ifin and ifnotin already proposed by #8087.

Note: See TracTickets for help on using tickets.
Back to Top