Django

Code

Ticket #3090 (closed: worksforme)

Opened 2 years ago

Last modified 1 year ago

[patch] Extend enclose tag process

Reported by: limodou@gmail.com Assigned to: nobody
Milestone: Component: Template system
Version: Keywords:
Cc: Triage Stage: Design decision needed
Has patch: 1 Needs documentation: 0
Needs tests: 1 Patch needs improvement: 0

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.

Attachments

template.patch (1.4 kB) - added by limodou@gmail.com on 12/03/06 01:07:57.

Change History

12/02/06 22:42:29 changed by adrian

  • component changed from Core framework to Template system.
  • summary changed from [Patch]Extend enclose tag process to Extend enclose tag process.

I don't see a patch here...Maybe you forgot to upload it?

12/03/06 01:07:57 changed by limodou@gmail.com

  • attachment template.patch added.

12/03/06 01:10:11 changed by limodou@gmail.com

  • summary changed from Extend enclose tag process to [patch]Extend enclose tag process.

I added the patch. I'm sorry forgot that.

12/06/06 16:19:47 changed by Eric Van Dewoestine <ervandew@yahoo.com>

I added a similar patch before stumbling on this ticket.

I took the liberty of marking mine as a duplicate: http://code.djangoproject.com/ticket/3100

12/12/06 00:28:38 changed by limodou

Hi, Eric:

I checked your patch, it's very similar with mine. And I hope the patch can be accepted.

01/22/07 03:21:43 changed by Simon G. <dev@simon.net.nz>

  • needs_docs set to 1.
  • summary changed from [patch]Extend enclose tag process to [patch] Extend enclose tag process.
  • needs_tests set to 1.
  • stage changed from Unreviewed to Design decision needed.

07/31/07 21:43:18 changed by anonymous

08/27/07 21:02:59 changed by anonymous

08/27/07 21:03:31 changed by anonymous

09/16/07 10:16:12 changed by ubernostrum

  • status changed from new to closed.
  • resolution set to worksforme.

The tag presented in this snippet at djangosnippets seems to show that what you want is possible. Closing "worksforme".


Add/Change #3090 ([patch] Extend enclose tag process)




Change Properties
Action