Opened 18 years ago

Last modified 15 years ago

#3090 closed enhancement

[Patch]Extend enclose tag process — at Initial Version

Reported by: limodou@… Owned by: nobody
Component: Template system Version:
Severity: normal Keywords:
Cc: Triage Stage: Design decision needed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I want to extend if to pyif tag. And I also want to implement elif tag support, just like:

    {% pyif i == 1 %}
        <p>i=1</p>
    {% elif i == 3 %}
        <p>i=3</p>
    {% else %}
        <p>other</p>
    {% endif %}

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:

elif token.token_type == TOKEN_BLOCK:
    if token.contents in parse_until:
        # put token back on token list so calling code knows why it terminated
        self.prepend_token(token)
        return nodelist
    try:
        command = token.contents.split()[0]
    except IndexError:
        self.empty_block_tag(token)

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:

Invalid block tag: 'elif'

So I made this patch so that django can just judge the tagname but not the whole token.contents.

Change History (0)

Note: See TracTickets for help on using tickets.
Back to Top