Fixed #12496 - Added code examples to built-in filter documentation. Thanks, Arthur Koziel.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12220 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
parent
f4998574d3
commit
e752d4984a
|
@ -1017,6 +1017,12 @@ addslashes
|
||||||
|
|
||||||
Adds slashes before quotes. Useful for escaping strings in CSV, for example.
|
Adds slashes before quotes. Useful for escaping strings in CSV, for example.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|addslashes }}
|
||||||
|
|
||||||
|
If ``value`` is ``"I'm using Django"``, the output will be ``"I\'m using Django"``.
|
||||||
|
|
||||||
.. templatefilter:: capfirst
|
.. templatefilter:: capfirst
|
||||||
|
|
||||||
capfirst
|
capfirst
|
||||||
|
@ -1024,6 +1030,12 @@ capfirst
|
||||||
|
|
||||||
Capitalizes the first character of the value.
|
Capitalizes the first character of the value.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|capfirst }}
|
||||||
|
|
||||||
|
If ``value`` is ``"django"``, the output will be ``"Django"``.
|
||||||
|
|
||||||
.. templatefilter:: center
|
.. templatefilter:: center
|
||||||
|
|
||||||
center
|
center
|
||||||
|
@ -1031,6 +1043,12 @@ center
|
||||||
|
|
||||||
Centers the value in a field of a given width.
|
Centers the value in a field of a given width.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
"{{ value|center:"15" }}"
|
||||||
|
|
||||||
|
If ``value`` is ``"Django"``, the output will be ``" Django "``.
|
||||||
|
|
||||||
.. templatefilter:: cut
|
.. templatefilter:: cut
|
||||||
|
|
||||||
cut
|
cut
|
||||||
|
@ -1194,6 +1212,13 @@ Escapes characters for use in JavaScript strings. This does *not* make the
|
||||||
string safe for use in HTML, but does protect you from syntax errors when using
|
string safe for use in HTML, but does protect you from syntax errors when using
|
||||||
templates to generate JavaScript/JSON.
|
templates to generate JavaScript/JSON.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|escapejs }}
|
||||||
|
|
||||||
|
If ``value`` is ``"testing\r\njavascript \'string" <b>escaping</b>"``,
|
||||||
|
the output will be ``"testing\\x0D\\x0Ajavascript \\x27string\\x22 \\x3Cb\\x3Eescaping\\x3C/b\\x3E"``.
|
||||||
|
|
||||||
.. templatefilter:: filesizeformat
|
.. templatefilter:: filesizeformat
|
||||||
|
|
||||||
filesizeformat
|
filesizeformat
|
||||||
|
@ -1320,6 +1345,12 @@ strings containing non-ASCII characters in a URL.
|
||||||
It's safe to use this filter on a string that has already gone through the
|
It's safe to use this filter on a string that has already gone through the
|
||||||
``urlencode`` filter.
|
``urlencode`` filter.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|iriencode }}
|
||||||
|
|
||||||
|
If ``value`` is ``"?test=1&me=2"``, the output will be ``"?test=1&me=2"``.
|
||||||
|
|
||||||
.. templatefilter:: join
|
.. templatefilter:: join
|
||||||
|
|
||||||
join
|
join
|
||||||
|
@ -1400,6 +1431,13 @@ linebreaksbr
|
||||||
Converts all newlines in a piece of plain text to HTML line breaks
|
Converts all newlines in a piece of plain text to HTML line breaks
|
||||||
(``<br />``).
|
(``<br />``).
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|linebreaksbr }}
|
||||||
|
|
||||||
|
If ``value`` is ``Joel\nis a slug``, the output will be ``Joel<br />is a
|
||||||
|
slug``.
|
||||||
|
|
||||||
.. templatefilter:: linenumbers
|
.. templatefilter:: linenumbers
|
||||||
|
|
||||||
linenumbers
|
linenumbers
|
||||||
|
@ -1407,6 +1445,22 @@ linenumbers
|
||||||
|
|
||||||
Displays text with line numbers.
|
Displays text with line numbers.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|linenumbers }}
|
||||||
|
|
||||||
|
If ``value`` is::
|
||||||
|
|
||||||
|
one
|
||||||
|
two
|
||||||
|
three
|
||||||
|
|
||||||
|
the output will be::
|
||||||
|
|
||||||
|
1. one
|
||||||
|
2. two
|
||||||
|
3. three
|
||||||
|
|
||||||
.. templatefilter:: ljust
|
.. templatefilter:: ljust
|
||||||
|
|
||||||
ljust
|
ljust
|
||||||
|
@ -1416,6 +1470,12 @@ Left-aligns the value in a field of a given width.
|
||||||
|
|
||||||
**Argument:** field size
|
**Argument:** field size
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
"{{ value|ljust:"10" }}"
|
||||||
|
|
||||||
|
If ``value`` is ``Django``, the output will be ``"Django "``.
|
||||||
|
|
||||||
.. templatefilter:: lower
|
.. templatefilter:: lower
|
||||||
|
|
||||||
lower
|
lower
|
||||||
|
@ -1451,12 +1511,17 @@ phone2numeric
|
||||||
~~~~~~~~~~~~~
|
~~~~~~~~~~~~~
|
||||||
|
|
||||||
Converts a phone number (possibly containing letters) to its numerical
|
Converts a phone number (possibly containing letters) to its numerical
|
||||||
equivalent. For example, ``'800-COLLECT'`` will be converted to
|
equivalent.
|
||||||
``'800-2655328'``.
|
|
||||||
|
|
||||||
The input doesn't have to be a valid phone number. This will happily convert
|
The input doesn't have to be a valid phone number. This will happily convert
|
||||||
any string.
|
any string.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|phone2numeric }}
|
||||||
|
|
||||||
|
If ``value`` is ``800-COLLECT``, the output will be ``800-2655328``.
|
||||||
|
|
||||||
.. templatefilter:: pluralize
|
.. templatefilter:: pluralize
|
||||||
|
|
||||||
pluralize
|
pluralize
|
||||||
|
@ -1468,6 +1533,9 @@ Example::
|
||||||
|
|
||||||
You have {{ num_messages }} message{{ num_messages|pluralize }}.
|
You have {{ num_messages }} message{{ num_messages|pluralize }}.
|
||||||
|
|
||||||
|
If ``num_messages`` is ``1``, the output will be ``You have 1 message.``
|
||||||
|
If ``num_messages`` is ``2`` the output will be ``You have 2 messages.``
|
||||||
|
|
||||||
For words that require a suffix other than ``'s'``, you can provide an alternate
|
For words that require a suffix other than ``'s'``, you can provide an alternate
|
||||||
suffix as a parameter to the filter.
|
suffix as a parameter to the filter.
|
||||||
|
|
||||||
|
@ -1527,6 +1595,12 @@ Right-aligns the value in a field of a given width.
|
||||||
|
|
||||||
**Argument:** field size
|
**Argument:** field size
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
"{{ value|rjust:"10" }}"
|
||||||
|
|
||||||
|
If ``value`` is ``Django``, the output will be ``" Django"``.
|
||||||
|
|
||||||
.. templatefilter:: safe
|
.. templatefilter:: safe
|
||||||
|
|
||||||
safe
|
safe
|
||||||
|
@ -1565,6 +1639,8 @@ Example::
|
||||||
|
|
||||||
{{ some_list|slice:":2" }}
|
{{ some_list|slice:":2" }}
|
||||||
|
|
||||||
|
If ``some_list`` is ``['a', 'b', 'c']``, the output will be ``['a', 'b']``.
|
||||||
|
|
||||||
.. templatefilter:: slugify
|
.. templatefilter:: slugify
|
||||||
|
|
||||||
slugify
|
slugify
|
||||||
|
@ -1684,6 +1760,12 @@ title
|
||||||
|
|
||||||
Converts a string into titlecase.
|
Converts a string into titlecase.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|title }}
|
||||||
|
|
||||||
|
If ``value`` is ``"my first post"``, the output will be ``"My First Post"``.
|
||||||
|
|
||||||
.. templatefilter:: truncatewords
|
.. templatefilter:: truncatewords
|
||||||
|
|
||||||
truncatewords
|
truncatewords
|
||||||
|
@ -1711,6 +1793,13 @@ closed immediately after the truncation.
|
||||||
This is less efficient than ``truncatewords``, so should only be used when it
|
This is less efficient than ``truncatewords``, so should only be used when it
|
||||||
is being passed HTML text.
|
is being passed HTML text.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|truncatewords_html:2 }}
|
||||||
|
|
||||||
|
If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be
|
||||||
|
``"<p>Joel is ...</p>"``.
|
||||||
|
|
||||||
.. templatefilter:: unordered_list
|
.. templatefilter:: unordered_list
|
||||||
|
|
||||||
unordered_list
|
unordered_list
|
||||||
|
@ -1761,6 +1850,13 @@ urlencode
|
||||||
|
|
||||||
Escapes a value for use in a URL.
|
Escapes a value for use in a URL.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|urlencode }}
|
||||||
|
|
||||||
|
If ``value`` is ``"http://www.example.org/foo?a=b&c=d"``, the output will be
|
||||||
|
``"http%3A//www.example.org/foo%3Fa%3Db%26c%3Dd"``.
|
||||||
|
|
||||||
.. templatefilter:: urlize
|
.. templatefilter:: urlize
|
||||||
|
|
||||||
urlize
|
urlize
|
||||||
|
@ -1806,6 +1902,12 @@ wordcount
|
||||||
|
|
||||||
Returns the number of words.
|
Returns the number of words.
|
||||||
|
|
||||||
|
For example::
|
||||||
|
|
||||||
|
{{ value|wordcount }}
|
||||||
|
|
||||||
|
If ``value`` is ``"Joel is a slug"``, the output will be ``4``.
|
||||||
|
|
||||||
.. templatefilter:: wordwrap
|
.. templatefilter:: wordwrap
|
||||||
|
|
||||||
wordwrap
|
wordwrap
|
||||||
|
|
Loading…
Reference in New Issue