﻿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
18400	Unexpected {% if %} behavior	Florian Apolloner	Susan Tan	"Given this simple template string:
{{{
{{ asd|length }}{% if asd|length > 1 %}Hi from an non existant variable!{% endif %}
}}}

The output will be (if asd is NOT in the context):
{{{
0Hi from an non existant variable!
}}}

The reason is as follows:

 * ''{{ asd|length }}'' resolves to ''!''|length'' which is 0
 * ''asd|length'' inside the if resolves to ''None|length'' which results in !'' (length returns !'' for every exception, len(None) isn't valid ;)) and !'' > 1 returns True in python :(

The easiest fix I can see is to make the if stuff perform usual template variable resolving which would result in the following patch: https://github.com/apollo13/django/commit/3782fc5862578951b7a6eb1eb97dca3a63267d44

The change breaks the template tests for me, hence I guess this ticket might need a design decission since it breaks behavior (a bit at least apperently ;))
"	Bug	closed	Template system	1.4	Normal	fixed	template, if, length	luyikei susan.tan.fleckerl@…	Accepted	1	1	0	0	0	0
