Ticket #3351: endblock.patch
File endblock.patch, 3.1 KB (added by , 18 years ago) |
---|
-
django/template/loader_tags.py
129 129 parser.__loaded_blocks.append(block_name) 130 130 except AttributeError: # parser.__loaded_blocks isn't a list yet 131 131 parser.__loaded_blocks = [block_name] 132 nodelist = parser.parse(('endblock',)) 132 try: 133 nodelist = parser.parse(('endblock','endblock %s' % block_name)) 134 except TemplateSyntaxError, err: 135 raise TemplateSyntaxError, str(err) + ' (unbalanced %s tags?)' % block_name 133 136 parser.delete_first_token() 134 137 return BlockNode(block_name, nodelist) 135 138 -
docs/templates.txt
253 253 if you want to add to the contents of a parent block instead of 254 254 completely overriding it. 255 255 256 * You can optionally name your ``{{ endblock }}`` tag with the same name 257 you gave the ``{{ block }}`` tag (for example, ``{{ endblock content }}``). 258 In larger templates this helps you see which ``{{ block }}`` tags are 259 being closed. 260 256 261 Finally, note that you can't define multiple ``{% block %}`` tags with the same 257 262 name in the same template. This limitation exists because a block tag works in 258 263 "both" directions. That is, a block tag doesn't just provide a hole to fill -- -
tests/regressiontests/templates/tests.py
390 390 'include03': ('{% include template_name %}', {'template_name': 'basic-syntax02', 'headline': 'Included'}, "Included"), 391 391 'include04': ('a{% include "nonexistent" %}b', {}, "ab"), 392 392 393 ### NAMED ENDBLOCKS ####################################################### 394 395 # Basic test 396 'namedendblocks01': ("1{% block first %}_{% block second %}2{% endblock second %}_{% endblock first %}3", {}, '1_2_3'), 397 398 # Unbalanced blocks 399 'namedendblocks02': ("1{% block first %}_{% block second %}2{% endblock first %}_{% endblock %}3", {}, template.TemplateSyntaxError), 400 'namedendblocks03': ("1{% block first %}_{% block second %}2{% endblock %}_{% endblock second %}3", {}, template.TemplateSyntaxError), 401 'namedendblocks04': ("1{% block first %}_{% block second %}2{% endblock second %}_{% endblock third %}3", {}, template.TemplateSyntaxError), 402 403 # Mixed named and unnamed endblocks 404 'namedendblocks05': ("1{% block first %}_{% block second %}2{% endblock %}_{% endblock first %}3", {}, '1_2_3'), 405 'namedendblocks06': ("1{% block first %}_{% block second %}2{% endblock second %}_{% endblock %}3", {}, '1_2_3'), 406 393 407 ### INHERITANCE ########################################################### 394 408 395 409 # Standard template with no inheritance