Ticket #4123: 4123.diff
File 4123.diff, 2.2 KB (added by , 17 years ago) |
---|
-
django/template/defaulttags.py
517 517 {% endif %}{% endif %}{% endif %} 518 518 519 519 but obviously much cleaner! 520 521 You can also use a literal string as a fallback value in case all 522 passed variables are False:: 523 524 {% firstof var1 var2 var3 "fallback value" %} 525 520 526 """ 521 bits = token. contents.split()[1:]527 bits = token.split_contents()[1:] 522 528 if len(bits) < 1: 523 529 raise TemplateSyntaxError, "'firstof' statement requires at least one argument" 524 530 return FirstOfNode(bits) -
tests/regressiontests/templates/tests.py
341 341 'firstof03': ('{% firstof a b c %}', {'a':0,'b':2,'c':0}, '2'), 342 342 'firstof04': ('{% firstof a b c %}', {'a':0,'b':0,'c':3}, '3'), 343 343 'firstof05': ('{% firstof a b c %}', {'a':1,'b':2,'c':3}, '1'), 344 'firstof06': ('{% firstof %}', {}, template.TemplateSyntaxError), 344 'firstof06': ('{% firstof a b c %}', {'b':0,'c':3}, '3'), 345 'firstof07': ('{% firstof a b "c" %}', {'a':0}, 'c'), 346 'firstof08': ('{% firstof a b "c and d" %}', {'a':0,'b':0}, 'c and d'), 347 'firstof09': ('{% firstof %}', {}, template.TemplateSyntaxError), 345 348 346 349 ### FOR TAG ############################################################### 347 350 'for-tag01': ("{% for val in values %}{{ val }}{% endfor %}", {"values": [1, 2, 3]}, "123"), -
docs/templates.txt
453 453 {% else %}{% if var3 %} 454 454 {{ var3 }} 455 455 {% endif %}{% endif %}{% endif %} 456 457 You can also use a literal string as a fallback value in case all 458 passed variables are False:: 456 459 460 {% firstof var1 var2 var3 "fallback value" %} 461 457 462 for 458 463 ~~~ 459 464