Ticket #9034: template_variable_doc.diff

File template_variable_doc.diff, 1.8 KB (added by oyvind, 16 years ago)
  • docs/howto/custom-template-tags.txt

    diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt
    index e1ddefe..99e4b29 100644
    a b Now your tag should begin to look like this::  
    525525
    526526You also have to change the renderer to retrieve the actual contents of the
    527527``date_updated`` property of the ``blog_entry`` object.  This can be
    528 accomplished by using the ``resolve_variable()`` function in
    529 ``django.template``. You pass ``resolve_variable()`` the variable name and the
     528accomplished by using the ``Variable`` class in ``django.template``.
     529You pass ``template.Variable`` the variable name and later call the
     530returned ``Variable`` instance method ``resolve`` using the
    530531current context, available in the ``render`` method::
    531532
    532533    from django import template
    533     from django.template import resolve_variable
    534534    import datetime
    535535    class FormatTimeNode(template.Node):
    536536        def __init__(self, date_to_be_formatted, format_string):
    537             self.date_to_be_formatted = date_to_be_formatted
     537            self.date_to_be_formatted = template.Variable(date_to_be_formatted)
    538538            self.format_string = format_string
    539539
    540540        def render(self, context):
    541541            try:
    542                 actual_date = resolve_variable(self.date_to_be_formatted, context)
     542                actual_date = self.date_to_be_formatted.resolve(context)
    543543                return actual_date.strftime(self.format_string)
    544544            except template.VariableDoesNotExist:
    545545                return ''
    546546
    547 ``resolve_variable`` will try to resolve ``blog_entry.date_updated`` and then
    548 format it accordingly.
     547The ``Variable`` instance self.date_to_be_formatted method ``resolve``, will
     548try to resolve ``blog_entry.date_updated`` and then format it accordingly.
    549549
    550550.. versionadded:: 1.0
    551551
Back to Top