id summary reporter owner description type status component version severity resolution keywords cc stage has_patch needs_docs needs_tests needs_better_patch easy ui_ux 11799 shortcoming in template language 'if' statement j@… nobody "Hi there, I'm pretty new to django so chances are that my remark is way out of line, but it seems there is a shortcoming in the django template language that forces you to do a lot of extra typing or do really ugly includes. The basic problem I have is this: Depending on the contents of a field in an object *and* on a boolean variable passed to the template I have to display an object from an object_list one way or the other. The only way that I've found to make this work looks like this: {{{ {% if titleonly %} {% ifequal item.itemtype 0 %}

{{ item.title }}


{% else %} {% include ""items/item_row.html"" %} {% endifequal %} {% else %} {% include ""items/item_row.html"" %} {% endif %} }}} The include is there to avoid really bad repetition of template code. Ideally this should have looked like: {{{ {% ifequal titleonly True and item.itemtype 0 %}

{{ item.title }}


{% else %} {% include ""items/item_row.html"" %} {% endif %} }}} The include could have been replaced in this example by the actual code to display the item. Am I doing something wrong or is this 'by design', and if so what is the motivation for crippling the template language in such a way that tons of special cases have to be worded as statements instead of providing a good general purpose tool ? " closed Template system 1.0 duplicate if ifequal inefficient Unreviewed 0 0 0 0 0 0