Code

Ticket #9034: template_variable_doc.diff

File template_variable_doc.diff, 1.8 KB (added by oyvind, 6 years ago)
Line 
1diff --git a/docs/howto/custom-template-tags.txt b/docs/howto/custom-template-tags.txt
2index e1ddefe..99e4b29 100644
3--- a/docs/howto/custom-template-tags.txt
4+++ b/docs/howto/custom-template-tags.txt
5@@ -525,27 +525,27 @@ Now your tag should begin to look like this::
6 
7 You also have to change the renderer to retrieve the actual contents of the
8 ``date_updated`` property of the ``blog_entry`` object.  This can be
9-accomplished by using the ``resolve_variable()`` function in
10-``django.template``. You pass ``resolve_variable()`` the variable name and the
11+accomplished by using the ``Variable`` class in ``django.template``.
12+You pass ``template.Variable`` the variable name and later call the
13+returned ``Variable`` instance method ``resolve`` using the
14 current context, available in the ``render`` method::
15 
16     from django import template
17-    from django.template import resolve_variable
18     import datetime
19     class FormatTimeNode(template.Node):
20         def __init__(self, date_to_be_formatted, format_string):
21-            self.date_to_be_formatted = date_to_be_formatted
22+            self.date_to_be_formatted = template.Variable(date_to_be_formatted)
23             self.format_string = format_string
24 
25         def render(self, context):
26             try:
27-                actual_date = resolve_variable(self.date_to_be_formatted, context)
28+                actual_date = self.date_to_be_formatted.resolve(context)
29                 return actual_date.strftime(self.format_string)
30             except template.VariableDoesNotExist:
31                 return ''
32 
33-``resolve_variable`` will try to resolve ``blog_entry.date_updated`` and then
34-format it accordingly.
35+The ``Variable`` instance self.date_to_be_formatted method ``resolve``, will
36+try to resolve ``blog_entry.date_updated`` and then format it accordingly.
37 
38 .. versionadded:: 1.0
39