Django {% if custom_template_tag > 0 %} does not work -
i've got these template tags
@register.assignment_tag def test1(): return 2 @register.simple_tag def test2(): return 2 in template i've got this
{% test1 test1_var %} {% if test1_var > 0 %}test1{% endif %} {% if test2 > 0 %}test2{% endif %} results in test1
what want template tag appears if greater 0, cannot believe assignment_tag right solution that. why test2 not work?
the test2 inside if statement not call template tag; can refer (non-existent) context variable. that's why assignment tag works, because set such variable.
if don't assignment tag, might consider doing whole comparison inside tag, outputs test1/test2 value directly.
Comments
Post a Comment