Reformatted docs/templates.txt to put headings in filter and tag references, so each tag/filter gets a permalink

git-svn-id: http://code.djangoproject.com/svn/django/trunk@1110 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-11-06 23:30:06 +00:00
parent 5defabca11
commit 92241e21b8
1 changed files with 586 additions and 453 deletions

View File

@ -289,18 +289,23 @@ available, and what they do.
Built-in tag reference Built-in tag reference
---------------------- ----------------------
``block`` block
Define a block that can be overridden by child templates. See `Template ~~~~~
inheritance`_ for more information.
``comment`` Define a block that can be overridden by child templates. See
Ignore everything between ``{% comment %}`` and ``{% endcomment %}`` `Template inheritance`_ for more information.
``cycle`` comment
Cycle among the given strings each time this tag is encountered. ~~~~~~~
Within a loop, cycles among the given strings each time through Ignore everything between ``{% comment %}`` and ``{% endcomment %}``
the loop::
cycle
~~~~~
Cycle among the given strings each time this tag is encountered.
Within a loop, cycles among the given strings each time through the loop::
{% for o in some_list %} {% for o in some_list %}
<tr class="{% cycle row1,row2 %}"> <tr class="{% cycle row1,row2 %}">
@ -308,51 +313,59 @@ Built-in tag reference
</tr> </tr>
{% endfor %} {% endfor %}
Outside of a loop, give the values a unique name the first time you call it, Outside of a loop, give the values a unique name the first time you call it,
then use that name each successive time through:: then use that name each successive time through::
<tr class="{% cycle row1,row2,row3 as rowcolors %}">...</tr> <tr class="{% cycle row1,row2,row3 as rowcolors %}">...</tr>
<tr class="{% cycle rowcolors %}">...</tr> <tr class="{% cycle rowcolors %}">...</tr>
<tr class="{% cycle rowcolors %}">...</tr> <tr class="{% cycle rowcolors %}">...</tr>
You can use any number of values, separated by commas. Make sure not to put You can use any number of values, separated by commas. Make sure not to put
spaces between the values -- only commas. spaces between the values -- only commas.
``debug`` debug
Output a whole load of debugging information, including the current context and ~~~~~
imported modules.
``extends`` Output a whole load of debugging information, including the current context and
Signal that this template extends a parent template. imported modules.
This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) uses extends
the literal value "base" as the name of the parent template to extend, or ``{% ~~~~~~~
extends variable %}`` uses the value of ``variable`` as the name of the parent
template to extend.
See `Template inheritance`_ for more information. Signal that this template extends a parent template.
``filter`` This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) uses
Filter the contents of the variable through variable filters. the literal value "base" as the name of the parent template to extend, or ``{%
extends variable %}`` uses the value of ``variable`` as the name of the parent
template to extend.
Filters can also be piped through each other, and they can have arguments -- See `Template inheritance`_ for more information.
just like in variable syntax.
Sample usage:: filter
~~~~~~
Filter the contents of the variable through variable filters.
Filters can also be piped through each other, and they can have arguments --
just like in variable syntax.
Sample usage::
{% filter escape|lower %} {% filter escape|lower %}
This text will be HTML-escaped, and will appear in all lowercase. This text will be HTML-escaped, and will appear in all lowercase.
{% endfilter %} {% endfilter %}
``firstof`` firstof
Outputs the first variable passed that is not False. Outputs nothing if all the ~~~~~~~
passed variables are False.
Sample usage:: Outputs the first variable passed that is not False. Outputs nothing if all the
passed variables are False.
Sample usage::
{% firstof var1 var2 var3 %} {% firstof var1 var2 var3 %}
This is equivalent to:: This is equivalent to::
{% if var1 %} {% if var1 %}
{{ var1 }} {{ var1 }}
@ -362,11 +375,11 @@ Built-in tag reference
{{ var3 }} {{ var3 }}
{% endif %}{% endif %}{% endif %} {% endif %}{% endif %}{% endif %}
but obviously much cleaner! for
~~~
``for`` Loop over each item in an array. For example, to display a list of athletes
Loop over each item in an array. For example, to display a list of athletes given ``athlete_list``::
given ``athlete_list``::
<ul> <ul>
{% for athlete in athlete_list %} {% for athlete in athlete_list %}
@ -374,9 +387,9 @@ Built-in tag reference
{% endfor %} {% endfor %}
</ul> </ul>
You can also loop over a list in reverse by using ``{% for obj in list reversed %}``. You can also loop over a list in reverse by using ``{% for obj in list reversed %}``.
The for loop sets a number of variables available within the loop: The for loop sets a number of variables available within the loop:
========================== ================================================ ========================== ================================================
Variable Description Variable Description
@ -393,10 +406,12 @@ Built-in tag reference
current one current one
========================== ================================================ ========================== ================================================
``if`` if
The ``{% if %}`` tag evaluates a variable, and if that variable is "true" (i.e. ~~
exists, is not empty, and is not a false boolean value) the contents of the
block are output:: The ``{% if %}`` tag evaluates a variable, and if that variable is "true" (i.e.
exists, is not empty, and is not a false boolean value) the contents of the
block are output::
{% if athlete_list %} {% if athlete_list %}
Number of athletes: {{ athlete_list|length }} Number of athletes: {{ athlete_list|length }}
@ -404,14 +419,14 @@ Built-in tag reference
No athletes. No athletes.
{% endif %} {% endif %}
In the above, if ``athlete_list`` is not empty, the number of athletes will be In the above, if ``athlete_list`` is not empty, the number of athletes will be
displayed by the ``{{ athlete_list|length }}`` variable. displayed by the ``{{ athlete_list|length }}`` variable.
As you can see, the ``if`` tag can take an option ``{% else %}`` clause that As you can see, the ``if`` tag can take an option ``{% else %}`` clause that
will be displayed if the test fails. will be displayed if the test fails.
``if`` tags may use ``or`` or ``not`` to test a number of variables or to negate ``if`` tags may use ``or`` or ``not`` to test a number of variables or to negate
a given variable:: a given variable::
{% if not athlete_list %} {% if not athlete_list %}
There are no athletes. There are no athletes.
@ -427,8 +442,8 @@ Built-in tag reference
stupid; it's not my fault). stupid; it's not my fault).
{% endif %} {% endif %}
For simplicity, ``if`` tags do not allow ``and`` clauses; use nested ``if`` For simplicity, ``if`` tags do not allow ``and`` clauses; use nested ``if``
tags instead:: tags instead::
{% if athlete_list %} {% if athlete_list %}
{% if coach_list %} {% if coach_list %}
@ -437,12 +452,14 @@ Built-in tag reference
{% endif %} {% endif %}
{% endif %} {% endif %}
``ifchanged`` ifchanged
Check if a value has changed from the last iteration of a loop. ~~~~~~~~~
The 'ifchanged' block tag is used within a loop. It checks its own rendered Check if a value has changed from the last iteration of a loop.
contents against its previous state and only displays its content if the value
has changed:: The 'ifchanged' block tag is used within a loop. It checks its own rendered
contents against its previous state and only displays its content if the value
has changed::
<h1>Archive for {{ year }}</h1> <h1>Archive for {{ year }}</h1>
@ -451,117 +468,127 @@ Built-in tag reference
<a href="{{ day|date:"M/d"|lower }}/">{{ day|date:"j" }}</a> <a href="{{ day|date:"M/d"|lower }}/">{{ day|date:"j" }}</a>
{% endfor %} {% endfor %}
``ifequal`` ifequal
Output the contents of the block if the two arguments equal each other. ~~~~~~~
Example:: Output the contents of the block if the two arguments equal each other.
Example::
{% ifequal user.id comment.user_id %} {% ifequal user.id comment.user_id %}
... ...
{% endifequal %} {% endifequal %}
As in the ``{% if %}`` tag, an ``{% else %}`` clause is optional. As in the ``{% if %}`` tag, an ``{% else %}`` clause is optional.
The arguments can be hard-coded strings, so the following is valid:: The arguments can be hard-coded strings, so the following is valid::
{% ifequal user.username "adrian" %} {% ifequal user.username "adrian" %}
... ...
{% endifequal %} {% endifequal %}
``ifnotequal`` ifnotequal
Just like ``ifequal``, except it tests that the two arguments are not equal. ~~~~~~~~~~
``load`` Just like ``ifequal``, except it tests that the two arguments are not equal.
Load a custom template tag set.
See `Custom tag and filter libraries`_ for more information. load
~~~~
``now`` Load a custom template tag set.
Display the date, formatted according to the given string.
Uses the same format as PHP's ``date()`` function (http://php.net/date) See `Custom tag and filter libraries`_ for more information.
with some custom extensions.
Available format strings: now
~~~
================ ====================================== ===================== Display the date, formatted according to the given string.
Format character Description Example output
================ ====================================== ===================== Uses the same format as PHP's ``date()`` function (http://php.net/date)
a ``'a.m.'`` or ``'p.m.'`` (Note that ``'a.m.'`` with some custom extensions.
Available format strings:
================ ====================================== =====================
Format character Description Example output
================ ====================================== =====================
a ``'a.m.'`` or ``'p.m.'`` (Note that ``'a.m.'``
this is slightly different than PHP's this is slightly different than PHP's
output, because this includes periods output, because this includes periods
to match Associated Press style.) to match Associated Press style.)
A ``'AM'`` or ``'PM'``. ``'AM'`` A ``'AM'`` or ``'PM'``. ``'AM'``
B Not implemented. B Not implemented.
d Day of the month, 2 digits with ``'01'`` to ``'31'`` d Day of the month, 2 digits with ``'01'`` to ``'31'``
leading zeros. leading zeros.
D Day of the week, textual, 3 letters. ``'Fri'`` D Day of the week, textual, 3 letters. ``'Fri'``
f Time, in 12-hour hours and minutes, ``'1'``, ``'1:30'`` f Time, in 12-hour hours and minutes, ``'1'``, ``'1:30'``
with minutes left off if they're zero. with minutes left off if they're zero.
Proprietary extension. Proprietary extension.
F Month, textual, long. ``'January'`` F Month, textual, long. ``'January'``
g Hour, 12-hour format without leading ``'1'`` to ``'12'`` g Hour, 12-hour format without leading ``'1'`` to ``'12'``
zeros. zeros.
G Hour, 24-hour format without leading ``'0'`` to ``'23'`` G Hour, 24-hour format without leading ``'0'`` to ``'23'``
zeros. zeros.
h Hour, 12-hour format. ``'01'`` to ``'12'`` h Hour, 12-hour format. ``'01'`` to ``'12'``
H Hour, 24-hour format. ``'00'`` to ``'23'`` H Hour, 24-hour format. ``'00'`` to ``'23'``
i Minutes. ``'00'`` to ``'59'`` i Minutes. ``'00'`` to ``'59'``
I Not implemented. I Not implemented.
j Day of the month without leading ``'1'`` to ``'31'`` j Day of the month without leading ``'1'`` to ``'31'``
zeros. zeros.
l Day of the week, textual, long. ``'Friday'`` l Day of the week, textual, long. ``'Friday'``
L Boolean for whether it's a leap year. ``True`` or ``False`` L Boolean for whether it's a leap year. ``True`` or ``False``
m Month, 2 digits with leading zeros. ``'01'`` to ``'12'`` m Month, 2 digits with leading zeros. ``'01'`` to ``'12'``
M Month, textual, 3 letters. ``'Jan'`` M Month, textual, 3 letters. ``'Jan'``
n Month without leading zeros. ``'1'`` to ``'12'`` n Month without leading zeros. ``'1'`` to ``'12'``
N Month abbreviation in Associated Press ``'Jan.'``, ``'Feb.'``, ``'March'``, ``'May'`` N Month abbreviation in Associated Press ``'Jan.'``, ``'Feb.'``, ``'March'``, ``'May'``
style. Proprietary extension. style. Proprietary extension.
O Difference to Greenwich time in hours. ``'+0200'`` O Difference to Greenwich time in hours. ``'+0200'``
P Time, in 12-hour hours, minutes and ``'1 a.m.'``, ``'1:30 p.m.'``, ``'midnight'``, ``'noon'``, ``'12:30 p.m.'`` P Time, in 12-hour hours, minutes and ``'1 a.m.'``, ``'1:30 p.m.'``, ``'midnight'``, ``'noon'``, ``'12:30 p.m.'``
'a.m.'/'p.m.', with minutes left off 'a.m.'/'p.m.', with minutes left off
if they're zero and the special-case if they're zero and the special-case
strings 'midnight' and 'noon' if strings 'midnight' and 'noon' if
appropriate. Proprietary extension. appropriate. Proprietary extension.
r RFC 822 formatted date. ``'Thu, 21 Dec 2000 16:01:07 +0200'`` r RFC 822 formatted date. ``'Thu, 21 Dec 2000 16:01:07 +0200'``
s Seconds, 2 digits with leading zeros. ``'00'`` to ``'59'`` s Seconds, 2 digits with leading zeros. ``'00'`` to ``'59'``
S English ordinal suffix for day of the ``'st'``, ``'nd'``, ``'rd'`` or ``'th'`` S English ordinal suffix for day of the ``'st'``, ``'nd'``, ``'rd'`` or ``'th'``
month, 2 characters. month, 2 characters.
t Not implemented. t Not implemented.
T Time zone of this machine. ``'EST'``, ``'MDT'`` T Time zone of this machine. ``'EST'``, ``'MDT'``
U Not implemented. U Not implemented.
w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday) w Day of the week, digits without ``'0'`` (Sunday) to ``'6'`` (Saturday)
leading zeros. leading zeros.
W ISO-8601 week number of year, with ``1``, ``23`` W ISO-8601 week number of year, with ``1``, ``23``
weeks starting on Monday. weeks starting on Monday.
y Year, 2 digits. ``'99'`` y Year, 2 digits. ``'99'``
Y Year, 4 digits. ``'1999'`` Y Year, 4 digits. ``'1999'``
z Day of the year. ``0`` to ``365`` z Day of the year. ``0`` to ``365``
Z Time zone offset in seconds. The ``-43200`` to ``43200`` Z Time zone offset in seconds. The ``-43200`` to ``43200``
offset for timezones west of UTC is offset for timezones west of UTC is
always negative, and for those east of always negative, and for those east of
UTC is always positive. UTC is always positive.
================ ====================================== ===================== ================ ====================================== =====================
Example:: Example::
It is {% now "jS F Y H:i" %} It is {% now "jS F Y H:i" %}
Note that you can backslash-escape a format string if you want to use the Note that you can backslash-escape a format string if you want to use the
"raw" value. In this example, "f" is backslash-escaped, because otherwise "raw" value. In this example, "f" is backslash-escaped, because otherwise
"f" is a format string that displays the time. The "o" doesn't need to be "f" is a format string that displays the time. The "o" doesn't need to be
escaped, because it's not a format character.:: escaped, because it's not a format character.::
It is the {% "jS o\f F" %} It is the {% "jS o\f F" %}
(Displays "It is the 4th of September" %} (Displays "It is the 4th of September" %}
``regroup`` regroup
Regroup a list of alike objects by a common attribute. ~~~~~~~
This complex tag is best illustrated by use of an example: say that ``people`` Regroup a list of alike objects by a common attribute.
is a list of ``Person`` objects that have ``first_name``, ``last_name``, and
``gender`` attributes, and you'd like to display a list that looks like: This complex tag is best illustrated by use of an example: say that ``people``
is a list of ``Person`` objects that have ``first_name``, ``last_name``, and
``gender`` attributes, and you'd like to display a list that looks like:
* Male: * Male:
* George Bush * George Bush
@ -572,7 +599,7 @@ Built-in tag reference
* Unknown: * Unknown:
* Pat Smith * Pat Smith
The following snippet of template code would accomplish this dubious task:: The following snippet of template code would accomplish this dubious task::
{% regroup people by gender as grouped %} {% regroup people by gender as grouped %}
<ul> <ul>
@ -586,45 +613,49 @@ Built-in tag reference
{% endfor %} {% endfor %}
</ul> </ul>
As you can see, ``{% regroup %}`` populates a variable with a list of objects As you can see, ``{% regroup %}`` populates a variable with a list of objects
with ``grouper`` and ``list`` attributes. ``grouper`` contains the item that with ``grouper`` and ``list`` attributes. ``grouper`` contains the item that
was grouped by; ``list`` contains the list of objects that share that was grouped by; ``list`` contains the list of objects that share that
``grouper``. In this case, ``grouper`` would be ``Male``, ``Female`` and ``grouper``. In this case, ``grouper`` would be ``Male``, ``Female`` and
``Unknown``, and ``list`` is the list of people with those genders. ``Unknown``, and ``list`` is the list of people with those genders.
Note that ``{% regroup %}`` does not work when the list to be grouped is not Note that ``{% regroup %}`` does not work when the list to be grouped is not
sorted by the key you are grouping by! This means that if your list of people sorted by the key you are grouping by! This means that if your list of people
was not sorted by gender, you'd need to make sure it is sorted before using it, was not sorted by gender, you'd need to make sure it is sorted before using it,
i.e.:: i.e.::
{% regroup people|dictsort:"gender" by gender as grouped %} {% regroup people|dictsort:"gender" by gender as grouped %}
``ssi`` ssi
Output the contents of a given file into the page. ~~~
Like a simple "include" tag, ``{% ssi %}`` includes the contents of another Output the contents of a given file into the page.
file -- which must be specified using an absolute path -- in the current
page:: Like a simple "include" tag, ``{% ssi %}`` includes the contents of another
file -- which must be specified using an absolute path -- in the current
page::
{% ssi /home/html/ljworld.com/includes/right_generic.html %} {% ssi /home/html/ljworld.com/includes/right_generic.html %}
If the optional "parsed" parameter is given, the contents of the included If the optional "parsed" parameter is given, the contents of the included
file are evaluated as template code, within the current context:: file are evaluated as template code, within the current context::
{% ssi /home/html/ljworld.com/includes/right_generic.html parsed %} {% ssi /home/html/ljworld.com/includes/right_generic.html parsed %}
Note that if you use ``{% ssi %}``, you'll need to define Note that if you use ``{% ssi %}``, you'll need to define
`ALLOWED_INCLUDE_ROOTS`_ in your Django settings, as a security measure. `ALLOWED_INCLUDE_ROOTS`_ in your Django settings, as a security measure.
.. _ALLOWED_INCLUDE_ROOTS: http://www.djangoproject.com/documentation/settings/#allowed-include-roots .. _ALLOWED_INCLUDE_ROOTS: http://www.djangoproject.com/documentation/settings/#allowed-include-roots
``templatetag`` templatetag
Output one of the bits used to compose template tags. ~~~~~~~~~~~
Since the template system has no concept of "escaping", to display one of the Output one of the syntax characters used to compose template tags.
bits used in template tags, you must use the ``{% templatetag %}`` tag.
The argument tells which template bit to output: Since the template system has no concept of "escaping", to display one of the
bits used in template tags, you must use the ``{% templatetag %}`` tag.
The argument tells which template bit to output:
================== ======= ================== =======
Argument Outputs Argument Outputs
@ -635,175 +666,264 @@ Built-in tag reference
``closevariable`` ``}}`` ``closevariable`` ``}}``
================== ======= ================== =======
``widthratio`` widthratio
For creating bar charts and such, this tag calculates the ratio of a given value ~~~~~~~~~~
to a maximum value, and then applies that ratio to a constant.
For example:: For creating bar charts and such, this tag calculates the ratio of a given value
to a maximum value, and then applies that ratio to a constant.
For example::
<img src='bar.gif' height='10' width='{% widthratio this_value max_value 100 %}' /> <img src='bar.gif' height='10' width='{% widthratio this_value max_value 100 %}' />
Above, if ``this_value`` is 175 and ``max_value`` is 200, the the image in the Above, if ``this_value`` is 175 and ``max_value`` is 200, the the image in the
above example will be 88 pixels wide (because 175/200 = .875; .875 * 100 = 87.5 above example will be 88 pixels wide (because 175/200 = .875; .875 * 100 = 87.5
which is rounded up to 88). which is rounded up to 88).
Built-in filter reference Built-in filter reference
------------------------- -------------------------
``add`` add
Adds the arg to the value. ~~~
``addslashes`` Adds the arg to the value.
Adds slashes. Useful for passing strings to JavaScript, for example.
``capfirst`` addslashes
Capitalizes the first character of the value. ~~~~~~~~~~
``center`` Adds slashes. Useful for passing strings to JavaScript, for example.
Centers the value in a field of a given width.
``cut``
Removes all values of arg from the given string.
``date`` capfirst
Formats a date according to the given format (same as the ``now`` tag). ~~~~~~~~
``default`` Capitalizes the first character of the value.
If value is unavailable, use given default.
``default_if_none`` center
If value is ``None``, use given default. ~~~~~~
``dictsort`` Centers the value in a field of a given width.
Takes a list of dicts, returns that list sorted by the property given in the
argument.
``dictsortreversed`` cut
Takes a list of dicts, returns that list sorted in reverse order by the property ~~~
given in the argument.
``divisibleby`` Removes all values of arg from the given string.
Returns true if the value is divisible by the argument.
``escape`` date
Escapes a string's HTML. ~~~~
``filesizeformat`` Formats a date according to the given format (same as the ``now`` tag).
Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102
bytes, etc).
``first`` default
Returns the first item in a list. ~~~~~~~
``fix_ampersands`` If value is unavailable, use given default.
Replaces ampersands with ``&amp;`` entities.
``floatformat`` default_if_none
Displays a floating point number as 34.2 (with one decimal places) - but ~~~~~~~~~~~~~~~
only if there's a point to be displayed.
``get_digit`` If value is ``None``, use given default.
Given a whole number, returns the requested digit of it, where 1 is the
right-most digit, 2 is the second-right-most digit, etc. Returns the
original value for invalid input (if input or argument is not an integer,
or if argument is less than 1). Otherwise, output is always an integer.
``join`` dictsort
Joins a list with a string, like Python's ``str.join(list)``. ~~~~~~~~
``length`` Takes a list of dicts, returns that list sorted by the property given in the
Returns the length of the value. Useful for lists. argument.
``length_is`` dictsortreversed
Returns a boolean of whether the value's length is the argument. ~~~~~~~~~~~~~~~~
``linebreaks`` Takes a list of dicts, returns that list sorted in reverse order by the
Converts newlines into <p> and <br />s. property given in the argument.
``linebreaksbr`` divisibleby
Converts newlines into <br />s. ~~~~~~~~~~~
``linenumbers`` Returns true if the value is divisible by the argument.
Displays text with line numbers.
``ljust`` escape
Left-aligns the value in a field of a given width. ~~~~~~
**Argument:** field size Escapes a string's HTML. Specifically, it makes these replacements:
``lower`` * ``"&"`` to ``"&amp;"``
Converts a string into all lowercase. * ``<`` to ``"&lt;"``
* ``>`` to ``"&gt;"``
* ``'"'`` (double quote) to ``"&quot;"``
``make_list`` filesizeformat
Returns the value turned into a list. For an integer, it's a list of ~~~~~~~~~~~~~~
digits. For a string, it's a list of characters.
``phone2numeric`` Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102
Takes a phone number and converts it in to its numerical equivalent. bytes, etc).
``pluralize`` first
Returns 's' if the value is not 1, for '1 vote' vs. '2 votes'. ~~~~~
``pprint`` Returns the first item in a list.
A wrapper around pprint.pprint -- for debugging, really.
``random`` fix_ampersands
Returns a random item from the list. ~~~~~~~~~~~~~~
``removetags`` Replaces ampersands with ``&amp;`` entities.
Removes a space separated list of [X]HTML tags from the output.
``rjust`` floatformat
Right-aligns the value in a field of a given width.
**Argument:** field size Displays a floating point number as 34.2 (with one decimal places) -- but only
if there's a point to be displayed.
``slice`` get_digit
Returns a slice of the list. ~~~~~~~~~
Uses the same syntax as Python's list slicing; see Given a whole number, returns the requested digit of it, where 1 is the
http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice right-most digit, 2 is the second-right-most digit, etc. Returns the original
for an introduction. value for invalid input (if input or argument is not an integer, or if argument
is less than 1). Otherwise, output is always an integer.
Example: ``{{ some_list|slice:":2" }}`` join
~~~~
``slugify`` Joins a list with a string, like Python's ``str.join(list)``.
Converts to lowercase, removes non-word characters (alphanumerics and
underscores) and converts spaces to hyphens. Also strips leading and
trailing whitespace.
``stringformat`` length
Formats the variable according to the argument, a string formatting specifier. ~~~~~~
This specifier uses Python string formating syntax, with the exception that
the leading "%" is dropped.
See http://docs.python.org/lib/typesseq-strings.html for documentation Returns the length of the value. Useful for lists.
of Python string formatting
``striptags`` length_is
Strips all [X]HTML tags. ~~~~~~~~~
``time`` Returns a boolean of whether the value's length is the argument.
Formats a time according to the given format (same as the ``now`` tag).
``timesince`` linebreaks
Formats a date as the time since that date (i.e. "4 days, 6 hours"). ~~~~~~~~~~
``title`` Converts newlines into <p> and <br />s.
Converts a string into titlecase.
``truncatewords`` linebreaksbr
Truncates a string after a certain number of words. ~~~~~~~~~~~~
**Argument:** Number of words to truncate after Converts newlines into <br />s.
``unordered_list`` linenumbers
Recursively takes a self-nested list and returns an HTML unordered list -- ~~~~~~~~~~~
WITHOUT opening and closing <ul> tags.
The list is assumed to be in the proper format. For example, if ``var`` contains Displays text with line numbers.
``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``,
then ``{{ var|unordered_list }}`` would return:: ljust
~~~~~
Left-aligns the value in a field of a given width.
**Argument:** field size
lower
~~~~~
Converts a string into all lowercase.
make_list
~~~~~~~~~
Returns the value turned into a list. For an integer, it's a list of
digits. For a string, it's a list of characters.
phone2numeric
~~~~~~~~~~~~~
Converts a phone number to its numerical equivalent.
pluralize
~~~~~~~~~
Returns 's' if the value is not 1, for '1 vote' vs. '2 votes'.
pprint
~~~~~~
A wrapper around pprint.pprint -- for debugging, really.
random
~~~~~~
Returns a random item from the list.
removetags
~~~~~~~~~~
Removes a space separated list of [X]HTML tags from the output.
rjust
~~~~~
Right-aligns the value in a field of a given width.
**Argument:** field size
slice
~~~~~
Returns a slice of the list.
Uses the same syntax as Python's list slicing. See
http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice
for an introduction.
Example: ``{{ some_list|slice:":2" }}``
slugify
~~~~~~~
Converts to lowercase, removes non-word characters (alphanumerics and
underscores) and converts spaces to hyphens. Also strips leading and trailing
whitespace.
stringformat
~~~~~~~~~~~~
Formats the variable according to the argument, a string formatting specifier.
This specifier uses Python string formating syntax, with the exception that
the leading "%" is dropped.
See http://docs.python.org/lib/typesseq-strings.html for documentation of
Python string formatting
striptags
~~~~~~~~~
Strips all [X]HTML tags.
time
~~~~
Formats a time according to the given format (same as the ``now`` tag).
timesince
~~~~~~~~~
Formats a date as the time since that date (i.e. "4 days, 6 hours").
title
~~~~~
Converts a string into titlecase.
truncatewords
~~~~~~~~~~~~~
Truncates a string after a certain number of words.
**Argument:** Number of words to truncate after
unordered_list
~~~~~~~~~~~~~~
Recursively takes a self-nested list and returns an HTML unordered list --
WITHOUT opening and closing <ul> tags.
The list is assumed to be in the proper format. For example, if ``var`` contains
``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``,
then ``{{ var|unordered_list }}`` would return::
<li>States <li>States
<ul> <ul>
@ -817,39 +937,52 @@ Built-in filter reference
</ul> </ul>
</li> </li>
``upper`` upper
Converts a string into all uppercase. ~~~~~
``urlencode`` Converts a string into all uppercase.
Escapes a value for use in a URL.
``urlize`` urlencode
Converts URLs in plain text into clickable links. ~~~~~~~~~
``urlizetrunc`` Escapes a value for use in a URL.
Converts URLs into clickable links, truncating URLs to the given character
limit.
**Argument:** Length to truncate URLs to urlize
~~~~~~
``wordcount`` Converts URLs in plain text into clickable links.
Returns the number of words.
``wordwrap`` urlizetrunc
Wraps words at specified line length. ~~~~~~~~~~~
**Argument:** number of words at which to wrap the text Converts URLs into clickable links, truncating URLs to the given character limit.
``yesno`` **Argument:** Length to truncate URLs to
Given a string mapping values for true, false and (optionally) None,
returns one of those strings according to the value:
========== ====================== ================================== wordcount
Value Argument Outputs ~~~~~~~~~
========== ====================== ==================================
``True`` ``"yeah,no,maybe"`` ``yeah`` Returns the number of words.
``False`` ``"yeah,no,maybe"`` ``no``
``None`` ``"yeah,no,maybe"`` ``maybe`` wordwrap
``None`` ``"yeah,no"`` ``"no"`` (converts None to False ~~~~~~~~
Wraps words at specified line length.
**Argument:** number of words at which to wrap the text
yesno
~~~~~
Given a string mapping values for true, false and (optionally) None,
returns one of those strings according to the value:
========== ====================== ==================================
Value Argument Outputs
========== ====================== ==================================
``True`` ``"yeah,no,maybe"`` ``yeah``
``False`` ``"yeah,no,maybe"`` ``no``
``None`` ``"yeah,no,maybe"`` ``maybe``
``None`` ``"yeah,no"`` ``"no"`` (converts None to False
if no mapping for None is given) if no mapping for None is given)
========== ====================== ================================== ========== ====================== ==================================