Changes between Initial Version and Version 12 of Ticket #3090
- Timestamp:
- Jul 29, 2009, 6:45:46 AM (15 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Ticket #3090
- Property Component Core framework → Template system
- Property Summary [Patch]Extend enclose tag process → Support for arguments on intermediate tag tokens (ex. {% if arg %}{% elif arg %}{% endif %})
- Property Needs documentation set
- Property Triage Stage Unreviewed → Design decision needed
- Property Resolution → invalid
- Property Status new → closed
-
Ticket #3090 – Description
initial v12 1 I want to extend `if` to `pyif` tag. And I also want to implement `elif` tag support, just like: 1 Currently the template functionality prevents creation of tags which have intermediate tags requiring arguments. 2 2 3 For instance: 3 4 {{{ 4 {% pyif i == 1 %} 5 <p>i=1</p> 6 {% elif i == 3 %} 7 <p>i=3</p> 8 {% else %} 9 <p>other</p> 10 {% endif %} 5 {% myif arg %} 6 first block 7 {% elif arg %} <-- current version would fail to parse this correctly because of the arg 8 second block 9 {% endmyif %} 11 10 }}} 12 11 13 So you can see `elif` has en expression. But I found current django `template/__init__.py` can not support enclose tag process just like `elif`, because it has extra info. And the code in `template/__init__.py` is: 14 15 {{{ 16 elif token.token_type == TOKEN_BLOCK: 17 if token.contents in parse_until: 18 # put token back on token list so calling code knows why it terminated 19 self.prepend_token(token) 20 return nodelist 21 try: 22 command = token.contents.split()[0] 23 except IndexError: 24 self.empty_block_tag(token) 25 }}} 26 27 So you can see django use `token.contents in parse_until` to determin if it encounter an enclose tag, and doesn't support extra info after the enclose tag. So if I extend `elif` and add extra expression, it'll failed and raise: 28 29 {{{ 30 Invalid block tag: 'elif' 31 }}} 32 33 So I made this patch so that django can just judge the tagname but not the whole token.contents. 12 The attached patch removes this restriction.