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
8296,"Allow template parser to parse until ""complex"" block node",julien,nobody,"For info, this was brought up in [1].
Currently, with block tags, you can only parse until a ""simple"" closure tag. For example: `{% endif %}` or `{% endfor %}`.
Now, it would be nice if you could parse until something more ""complex"" like `{% elseif blah and blahblah %}`. By ""complex"" I mean a tag that requires some parameters.
Here I'm not asking for an `elseif` tag in particular, but I'd like to allow the parser to also consider ""complex"" closure tags.
For example, a direct application of this would be a suggestion for a `{% withblock %}` tag. Here's a suggested syntax:
{{{
{% withblock as myurl %}
{% url path.to.some_view arg1,arg2,name1=value1 %}
{% and as var %}
{% whatever %}
{% in %}
Click the link: {{ var }}.
{% endwithblock %}
}}}
Currently the `{% and as var %}` tag cannot be recognized. The problem is in `django.template.Parser.parse()`:
{{{
...
elif token.token_type == TOKEN_BLOCK:
if token.contents in parse_until:
...
}}}
It basically checks if the tag's hard string name is in the list. The attached patch, which is *backward compatible*, only looks at the first piece of text in the node, namely the tag's name. With that, in your tag you could parse the block like follows:
{{{
nodelist = parser.parse(('and', 'in')) # Parse until {% and as var %} or {% in %}
}}}
[1] http://groups.google.com/group/django-developers/browse_thread/thread/c81a9fe156af71e7",,closed,Template system,master,,duplicate,,me@…,Design decision needed,1,0,0,0,,