﻿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
16355	TemplateSyntaxError raised by do_block do not allow using doublicate block	netinsideout@…	anonymous	"This ticket is related to changeset: https://code.djangoproject.com/changeset/12655 and ticket: 
https://code.djangoproject.com/ticket/10975
I realised that django template system supports construction like this:

{{{
{% ifnotequal setting u'inverted'%}
   {% block a %}{% endblock %}
   {% block b %}{% endblock %}
{% else %}
   {% block b %}{% endblock %}
   {% block a %}{% endblock %}
{% endifnotequal %}
}}}

but function do_block raises TemplateSyntaxError when checking for duplicate block in template. 

Original in django 1.3:
django/template/loader_tags.py
{{{
def do_block(parser, token):
    """"""
    Define a block that can be overridden by child templates.
    """"""
    bits = token.contents.split()
    if len(bits) != 2:
        raise TemplateSyntaxError(""'%s' tag takes only one argument"" % bits[0])
    block_name = bits[1]
    # Keep track of the names of BlockNodes found in this template, so we can
    # check for duplication.
    try:
        if block_name in parser.__loaded_blocks:
            raise TemplateSyntaxError(""'%s' tag with name '%s' appears more than once"" % (bits[0], block_name))
        parser.__loaded_blocks.append(block_name)
    except AttributeError: # parser.__loaded_blocks isn't a list yet
        parser.__loaded_blocks = [block_name]
    nodelist = parser.parse(('endblock', 'endblock %s' % block_name))
    parser.delete_first_token()
    return BlockNode(block_name, nodelist)
}}}

I just removed 2 lines and construction like above starts working as expected.

{{{
def do_block(parser, token):
    """"""
    Define a block that can be overridden by child templates.
    """"""
    bits = token.contents.split()
    if len(bits) != 2:
        raise TemplateSyntaxError(""'%s' tag takes only one argument"" % bits[0])
    block_name = bits[1]
    # Keep track of the names of BlockNodes found in this template, so we can
    # check for duplication.
    try:
        parser.__loaded_blocks.append(block_name)
    except AttributeError: # parser.__loaded_blocks isn't a list yet
        parser.__loaded_blocks = [block_name]
    nodelist = parser.parse(('endblock', 'endblock %s' % block_name))
    parser.delete_first_token()
    return BlockNode(block_name, nodelist)
}}}
"	Bug	closed	Template system	1.3	Normal	wontfix			Design decision needed	0	0	0	0	0	0
