Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Proposal: Enhanced simple-tag decorator #1105
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  2 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Julien Phalip  
View profile  
 More options Sep 16 2008, 8:03 am
From: Julien Phalip <jpha...@gmail.com>
Date: Tue, 16 Sep 2008 05:03:49 -0700 (PDT)
Local: Tues, Sep 16 2008 8:03 am
Subject: Proposal: Enhanced simple-tag decorator #1105
This is a call to review ticket #1105. The proposed patch is fully
functional, backwards-compatible and contains tests and documentation.
http://code.djangoproject.com/ticket/1105

Currently it is not possible to access the context from within a
simple_tag, and there is no "simple" way to create block tags. Both of
these tasks imply using some boilerplate code to parse the tokens,
manage variables, etc.

The patch in #1105 addresses these two issues. What you can now do:

1) Get access to the context:

@register.simple_tag(takes_context=True)
def mytag(context, arg1, arg2):
    ...

2) Easily create simple block tags:

@register.simple_tag(takes_nodelist=True)
def mytag(nodelist, arg1, arg2):
    ...

{% mytag some_var "some_string" %}
    ...
{% endmytag %}

3) Or even do both:

@register.simple_tag(takes_context=True, takes_nodelist=True)
def mytag(context, nodelist, arg1, arg2):
    ...

These enhancements should make the development of simple template tags
much faster. The patch's tests also make sure that it remains
backwards-compatible and won't break existing code. I've added this to
the Version 1.1 feature wish-list.

Any feedback welcome, thanks!

Julien :)


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Simon Willison  
View profile  
 More options Sep 16 2008, 11:55 am
From: Simon Willison <si...@simonwillison.net>
Date: Tue, 16 Sep 2008 08:55:00 -0700 (PDT)
Subject: Re: Proposal: Enhanced simple-tag decorator #1105
On Sep 16, 1:03 pm, Julien Phalip <jpha...@gmail.com> wrote:

> This is a call to review ticket #1105. The proposed patch is fully
> functional, backwards-compatible and contains tests and documentation.http://code.djangoproject.com/ticket/1105

> Currently it is not possible to access the context from within a
> simple_tag, and there is no "simple" way to create block tags. Both of
> these tasks imply using some boilerplate code to parse the tokens,
> manage variables, etc.

+1, I love it. I've been using this in my own projects for ages.

Cheers,

Simon


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »