Changes between Version 43 and Version 44 of BackwardsIncompatibleChanges


Ignore:
Timestamp:
11/26/05 17:33:52 (9 years ago)
Author:
rjwittams
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • BackwardsIncompatibleChanges

    v43 v44  
    369369== Changed the way custom template tags and filters are registered ==
    370370
    371 As of [], we changed the way custom template tags and filters are registered. If you've written custom template tags or filters, you'll need to make a couple of changes:
     371As of [1443], we changed the way custom template tags and filters are registered. If you've written custom template tags or filters, you'll need to make a couple of changes:
    372372
    373373=== Filter arguments ===
     
    413413If you're using the undocumented template decorators (simple_tag and inclusion_tag), change your calls to be members of the library class.
    414414
    415 [INSERT EXAMPLE HERE]
     415register.simple_tag(func)
     416
     417register.inclusion_tag('template/name')(func)
     418
     419=== Change template tags that use filters ===
     420
     421Filters are compiled at compile time now.
     422
     423Old way:
     424{{{
     425
     426class SomethingNode(Node):
     427    def __init__(self, filter_string):
     428        self.filter_string = filter_string
     429
     430    def render(self, context):
     431        var = render_variable_with_filters(self.filter_string, context)
     432        return var
     433
     434def do_something(parser, token):
     435    filter_string = bits[1]
     436    return SomethingNode(filter_string)
     437
     438}}}
     439
     440New way:
     441{{{
     442
     443class SomethingNode(Node):
     444    def __init__(self, filter_expr):
     445        self.filter_expr = filter_expr
     446
     447    def render(self, context):
     448        var = self.filter_expr.resolve(context)
     449        return var
     450
     451def do_something(parser, token):
     452    filter_string = bits[1]
     453    filter_expr = parser.compile_filter(filter_string)
     454    return SomethingNode(filter_expr)
     455
     456}}}
    416457
    417458See [http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-filters Writing custom template filters] and [http://www.djangoproject.com/documentation/templates_python/#writing-custom-template-tags Writing custom template tags] for full documentation.
Back to Top