Author: mtredinnick
Date: 2007-09-13 18:30:26 -0500 (Thu, 13 Sep 2007)
New Revision: 6143
Modified:
django/trunk/docs/templates_python.txt
Log:
Fixed #4793 -- Tweaked custom filter documentation a little to possibly reduce
some confusion. Thanks, SmileyChris.
Modified: django/trunk/docs/templates_python.txt
===================================================================
--- django/trunk/docs/templates_python.txt 2007-09-13 23:09:40 UTC (rev
6142)
+++ django/trunk/docs/templates_python.txt 2007-09-13 23:30:26 UTC (rev
6143)
@@ -642,7 +642,23 @@
"Converts a string into all lowercase"
return value.lower()
-When you've written your filter definition, you need to register it with
+Template filters which expect strings
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+If you're writing a template filter which only expects a string as the first
+argument, you should use the included decorator ``stringfilter``. This will
+convert an object to it's string value before being passed to your function::
+
+ from django.template.defaultfilters import stringfilter
+
+ @stringfilter
+ def lower(value):
+ return value.lower()
+
+Registering a custom filters
+~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+
+Once you've written your filter definition, you need to register it with
your ``Library`` instance, to make it available to Django's template language::
register.filter('cut', cut)
@@ -658,28 +674,18 @@
decorator instead::
@register.filter(name='cut')
+ @stringfilter
def cut(value, arg):
return value.replace(arg, '')
@register.filter
+ @stringfilter
def lower(value):
return value.lower()
If you leave off the ``name`` argument, as in the second example above, Django
will use the function's name as the filter name.
-Template filters which expect strings
-~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
-If you are writing a template filter which only expects a string as the first
-argument, you should use the included decorator ``stringfilter`` which will
convert
-an object to it's string value before being passed to your function::
-
- from django.template.defaultfilters import stringfilter
-
- @stringfilter
- def lower(value):
- return value.lower()
-
Writing custom template tags
----------------------------
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-updates?hl=en
-~----------~----~----~----~------~----~------~--~---