Cheers to limodou for getting me thinking about this. The only problem with his implementation is that it doesn't support Django's "." syntax for accessing array/dict elements. In the Django style of allowing simple syntax for designers while allowing for greater flexibility, and less template duplication for conditionals that were previously impossible to represent in templates, I modified Django's built-in If tag.
This is an adaptation/enhancement to Django's built in IfNode {% if ... %} that combines if ifequal ifnotequal into one and then adds even more. This
Supports
1. ==, !=
2. not ....
3. v in (1,"y",z)
4. <=, <, >=, >
5. nesting (True and (False or (True or False)))
How to use it:
{% pyif i == 1 or (5 >= i and i != 7) and user.first_name in ('John', 'Jacob') %}
'Tis true.
{% else %}
'Tis false.
{% endif %}
I hope you like it.
- template
- tag
- templatetag
- if
- conditional
- ifequal
- ifnotequal
The {% widthratio %} template tag is under appreciated! Here, it's combined with CSS to create a bar graphic for the results of an election (this example comes from [this page](http://flickr.com/photos/postneo/405239750/in/photostream/), but has been modified slightly for simplicity's sake).
The widthratio tag can be used to create all sorts of graphs and charts, as well as things like tag clouds. Here, we pass it the number of votes for a candidate, the total number of votes in the election, and the integer 190, which is the width, in pixels, of a "full" bar on the bar graph. In other words, 100% = 190 pixels.
It works great!
- template
- templatetag
- widthratio
- graph
- infographic