Changes between Initial Version and Version 12 of Ticket #3090


Ignore:
Timestamp:
Jul 29, 2009, 6:45:46 AM (15 years ago)
Author:
Russell Keith-Magee
Comment:

Following discussion on django-developers, it looks like this ticket may have been closed in error - the snippet may solve the same problem (elseif/case), but doesn't address the core issue of the ticket. The description on #3100, which was closed as a duplicate of this ticket, is much more enlightening as to the actual problem. To that end, I've reopened #3100.

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #3090

    • Property Component Core frameworkTemplate system
    • Property Summary [Patch]Extend enclose tag processSupport for arguments on intermediate tag tokens (ex. {% if arg %}{% elif arg %}{% endif %})
    • Property Needs documentation set
    • Property Triage Stage UnreviewedDesign decision needed
    • Property Resolutioninvalid
    • Property Status newclosed
  • 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:
     1Currently the template functionality prevents creation of tags which have intermediate tags requiring arguments.
    22
     3For instance:
    34{{{
    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 %}
    1110}}}
    1211
    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.
     12The attached patch removes this restriction.
Back to Top