Fixed typo in template docs -- Thanks, Nicholas Riley and Robin Munn!

git-svn-id: http://code.djangoproject.com/svn/django/trunk@145 bcc190cf-cafb-0310-a4f2-bffc1f526a37
This commit is contained in:
Adrian Holovaty 2005-07-17 15:15:26 +00:00
parent 0b62adddb2
commit 136d78b86e
1 changed files with 163 additions and 163 deletions

View File

@ -25,12 +25,12 @@ Below is a minimal template that illustrates the basic parts of a
template. Each element will be explained later in this document.:: template. Each element will be explained later in this document.::
{% extends "base_generic" %} {% extends "base_generic" %}
{% block title %}{{ section.title }}{% endblock %} {% block title %}{{ section.title }}{% endblock %}
{% block content %} {% block content %}
<h1>{{ section.title }}</h1> <h1>{{ section.title }}</h1>
{% for story in story_list %} {% for story in story_list %}
<h2> <h2>
<a href="{{ story.get_absolute_url }}"> <a href="{{ story.get_absolute_url }}">
@ -47,7 +47,7 @@ What's a variable?
Variables look like this: ``{{ variable }}``. When the template engine Variables look like this: ``{{ variable }}``. When the template engine
encounters a variable, it evaluates that variable and replaces the variable with encounters a variable, it evaluates that variable and replaces the variable with
the result. Many variables will be structures with named attributes; you can the result. Many variables will be structures with named attributes; you can
"drill down" into these structures with dots (``.``), so in the above example "drill down" into these structures with dots (``.``), so in the above example
``{{ section.title }}`` will be replaced with the ``title`` attribute of the ``{{ section.title }}`` will be replaced with the ``title`` attribute of the
``section`` object. ``section`` object.
@ -57,7 +57,7 @@ variable will be replaced by nothingness.
See `Using the built-in reference`_, below, for help on finding what variables See `Using the built-in reference`_, below, for help on finding what variables
are available in a given template. are available in a given template.
Variables may be modified before being displayed by **filters**. Variables may be modified before being displayed by **filters**.
What's a filter? What's a filter?
================ ================
@ -68,8 +68,8 @@ as you might have guessed, lowercases the text passed through it.
We use the pipe character to apply filters to emphasize the analogy with filters We use the pipe character to apply filters to emphasize the analogy with filters
on a water pipe: text enters one side, has some operation performed on it, and on a water pipe: text enters one side, has some operation performed on it, and
"flows" out the other side. Filters may be "chained"; the output of one filter "flows" out the other side. Filters may be "chained"; the output of one filter
applied to the next: ``{{ text|escape|linebreaks }}`` is a common idiom for applied to the next: ``{{ text|escape|linebreaks }}`` is a common idiom for
escaping text contents and then converting line breaks to ``<p>`` tags. escaping text contents and then converting line breaks to ``<p>`` tags.
Certain filters take arguments; a filter argument looks like this: ``{{ Certain filters take arguments; a filter argument looks like this: ``{{
@ -104,7 +104,7 @@ It's easiest to understand template inheritance by starting with an example::
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css" />
<title>{% block title %}My Amazing Site{% endblock %}</title> <title>{% block title %}My Amazing Site{% endblock %}</title>
</head> </head>
<body> <body>
<div id="sidebar"> <div id="sidebar">
{% block sidebar %} {% block sidebar %}
@ -114,34 +114,34 @@ It's easiest to understand template inheritance by starting with an example::
</ul> </ul>
{% endblock %} {% endblock %}
</div> </div>
<div id="content"> <div id="content">
{% block content %}{% endblock %} {% block content %}{% endblock %}
</div> </div>
</body> </body>
This template, which we'll call ``base.html`` defines a simple HTML skeleton This template, which we'll call ``base.html`` defines a simple HTML skeleton
document that you might use for a simple two-column page. This template document that you might use for a simple two-column page. This template
won't actually be used directly on any pages, but other "child" templates will won't actually be used directly on any pages, but other "child" templates will
extend it and fill in the empty blocks with content. extend it and fill in the empty blocks with content.
I've used the ``{% block %}`` tag to define the three blocks that child templates I've used the ``{% block %}`` tag to define the three blocks that child templates
will fill in. All that the ``block`` tag does is to signal to the template engine will fill in. All that the ``block`` tag does is to signal to the template engine
that a child template may override those portions of the template. that a child template may override those portions of the template.
To use this template, I might define a child template as follows:: To use this template, I might define a child template as follows::
{% extends "base" %} {% extends "base" %}
{% block title %}My Amazing Blog{% endblock %} {% block title %}My Amazing Blog{% endblock %}
{% block content %} {% block content %}
{% for entry in blog_entries %} <h2>{{ entry.title }}</h2> <p>{{ entry.body {% for entry in blog_entries %} <h2>{{ entry.title }}</h2> <p>{{ entry.body
}}</p> {% endfor %} }}</p> {% endfor %}
{% endblock %} {% endblock %}
The ``{% extends %}`` tag is the key here; it tells the template engine that The ``{% extends %}`` tag is the key here; it tells the template engine that
this template "extends" another template. When this template is evaluated, this template "extends" another template. When this template is evaluated,
the first step the template engine will perform is to locate the parent the first step the template engine will perform is to locate the parent
@ -159,7 +159,7 @@ Depending on the value of ``blog_entries``, the output might look like::
<link rel="stylesheet" href="style.css" /> <link rel="stylesheet" href="style.css" />
<title>My Amazing Blog</title> <title>My Amazing Blog</title>
</head> </head>
<body> <body>
<div id="sidebar"> <div id="sidebar">
<ul> <ul>
@ -167,11 +167,11 @@ Depending on the value of ``blog_entries``, the output might look like::
<li><a href="/blog/">Blog</a></li> <li><a href="/blog/">Blog</a></li>
</ul> </ul>
</div> </div>
<div id="content"> <div id="content">
<h2>Entry one</h2> <h2>Entry one</h2>
<p>This is my first entry.</p> <p>This is my first entry.</p>
<h2>Entry two</h2> <h2>Entry two</h2>
<p>This is my second entry.</p> <p>This is my second entry.</p>
</div> </div>
@ -188,25 +188,25 @@ inheritance is possible, and indeed, quite useful.
Here are some tips for working with inheritance: Here are some tips for working with inheritance:
* More ``{% block %}`` tags in your base templates are better. Remember, * More ``{% block %}`` tags in your base templates are better. Remember,
child templates do not have to define all parent blocks, so you can child templates do not have to define all parent blocks, so you can
fill in reasonable defaults in a number of blocks, then only define fill in reasonable defaults in a number of blocks, then only define
the ones you need later on. the ones you need later on.
* If you find yourself reproducing the same content in a number of * If you find yourself reproducing the same content in a number of
documents, it probably means you should move that content to a documents, it probably means you should move that content to a
new ``{% block %}`` in a parent template. new ``{% block %}`` in a parent template.
* We often prefer to use three-level inheritance: a single base template * We often prefer to use three-level inheritance: a single base template
for the entire site, a set of mid-level templates for each section of for the entire site, a set of mid-level templates for each section of
the site, and then the individual templates for each page. This the site, and then the individual templates for each page. This
maximizes code reuse, and makes it easier to add items to shared maximizes code reuse, and makes it easier to add items to shared
content areas (like section-wide navigation). content areas (like section-wide navigation).
* If you need to get the content of the block from the parent template, * If you need to get the content of the block from the parent template,
the ``{{ block.super }}`` variable will do the trick. This is useful the ``{{ block.super }}`` variable will do the trick. This is useful
if you want to add to the contents of a parent block instead of if you want to add to the contents of a parent block instead of
completely overriding it. completely overriding it.
Using the built-in reference Using the built-in reference
============================ ============================
@ -247,9 +247,9 @@ As mentioned above, certain applications will provide custom tag and filter
libraries. To access them in a template, use the ``{% load %}`` tag:: libraries. To access them in a template, use the ``{% load %}`` tag::
{% load comments %} {% load comments %}
{% comment_form for blogs.entries entry.id with is_public yes %} {% comment_form for blogs.entries entry.id with is_public yes %}
In the above, the ``load`` tag loads the ``comments`` tag library, which then In the above, the ``load`` tag loads the ``comments`` tag library, which then
makes the ``comment_form`` tag available for use. Consult the documentation makes the ``comment_form`` tag available for use. Consult the documentation
area in your admin to find the list of custom libraries in your installation. area in your admin to find the list of custom libraries in your installation.
@ -268,68 +268,68 @@ Built-in tag reference
``block`` ``block``
Define a block that can be overridden by child templates. See `Template Define a block that can be overridden by child templates. See `Template
inheritance`_ for more information. inheritance`_ for more information.
``comment`` ``comment``
Ignore everything between ``{% comment %}`` and ``{% endcomment %}`` Ignore everything between ``{% comment %}`` and ``{% endcomment %}``
``cycle`` ``cycle``
Cycle among the given strings each time this tag is encountered. Cycle among the given strings each time this tag is encountered.
Within a loop, cycles among the given strings each time through Within a loop, cycles among the given strings each time through
the loop:: the loop::
{% for o in some_list %} {% for o in some_list %}
<tr class="{% cycle row1,row2 %}"> <tr class="{% cycle row1,row2 %}">
... ...
</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 Output a whole load of debugging information, including the current context and
imported modules. imported modules.
``extends`` ``extends``
Signal that this template extends a parent template. Signal that this template extends a parent template.
This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) uses This tag may be used in two ways: ``{% extends "base" %}`` (with quotes) uses
the literal value "base" as the name of the parent template to extend, or ``{% 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 extends variable %}`` uses the value of ``variable`` as the name of the parent
template to extend. template to extend.
See `Template inheritance`_ for more information. See `Template inheritance`_ for more information.
``filter`` ``filter``
Filter the contents of the blog through variable filters. Filter the contents of the variable through variable filters.
Filters can also be piped through each other, and they can have arguments -- Filters can also be piped through each other, and they can have arguments --
just like in variable syntax. just like in variable syntax.
Sample usage:: 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 Outputs the first variable passed that is not False. Outputs nothing if all the
passed variables are False. passed variables are False.
Sample usage:: Sample usage::
{% firstof var1 var2 var3 %} {% firstof var1 var2 var3 %}
This is equivalent to:: This is equivalent to::
{% if var1 %} {% if var1 %}
{{ var1 }} {{ var1 }}
{% else %}{% if var2 %} {% else %}{% if var2 %}
@ -337,23 +337,23 @@ Built-in tag reference
{% else %}{% if var3 %} {% else %}{% if var3 %}
{{ var3 }} {{ var3 }}
{% endif %}{% endif %}{% endif %} {% endif %}{% endif %}{% endif %}
but obviously much cleaner! 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 %}
<li>{{ athlete.name }}</li> <li>{{ athlete.name }}</li>
{% 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
========================== ================================================ ========================== ================================================
@ -364,96 +364,96 @@ Built-in tag reference
``forloop.parentloop`` For nested loops, this is the loop "above" the ``forloop.parentloop`` For nested loops, this is the loop "above" the
current one current one
========================== ================================================ ========================== ================================================
``if`` ``if``
The ``{% if %}`` tag evaluates a variable, and if that variable is "true" (i.e. 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 exists, is not empty, and is not a false boolean value) the contents of the
block are output:: block are output::
{% if athlete_list %} {% if athlete_list %}
Number of athletes: {{ athlete_list|count }} Number of athletes: {{ athlete_list|count }}
{% else %} {% else %}
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|count }}`` variable. displayed by the ``{{ athlete_list|count }}`` 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.
{% endif %} {% endif %}
{% if athlete_list or coach_list %} {% if athlete_list or coach_list %}
There are some athletes or some coaches. There are some athletes or some coaches.
{% endif %} {% endif %}
{% if not athlete_list or coach_list %} {% if not athlete_list or coach_list %}
There are no athletes or there are some coaches (OK, so There are no athletes or there are some coaches (OK, so
writing English translations of boolean logic sounds writing English translations of boolean logic sounds
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 %}
Number of athletes: {{ athlete_list|count }}. Number of athletes: {{ athlete_list|count }}.
Number of coaches: {{ coach_list|count }}. Number of coaches: {{ coach_list|count }}.
{% endif %} {% endif %}
{% endif %} {% endif %}
``ifchanged`` ``ifchanged``
Check if a value has changed from the last iteration of a loop. 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 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 contents against its previous state and only displays its content if the value
has changed:: has changed::
<h1>Archive for {{ year }}</h1> <h1>Archive for {{ year }}</h1>
{% for date in days %} {% for date in days %}
{% ifchanged %}<h3>{{ date|date:"F" }}</h3>{% endifchanged %} {% ifchanged %}<h3>{{ date|date:"F" }}</h3>{% endifchanged %}
<a href="{{ date|date:"M/d"|lower }}/">{{ date|date:"j" }}</a> <a href="{{ date|date:"M/d"|lower }}/">{{ date|date:"j" }}</a>
{% endfor %} {% endfor %}
``ifnotequal`` ``ifnotequal``
Output the contents of the block if the two arguments do not equal each other. Output the contents of the block if the two arguments do not equal each other.
Example:: Example::
{% ifnotequal user.id_ comment.user_id %} {% ifnotequal user.id_ comment.user_id %}
... ...
{% endifnotequal %} {% endifnotequal %}
``load`` ``load``
Load a custom template tag set. Load a custom template tag set.
See `Custom tag and filter libraries`_ for more information. See `Custom tag and filter libraries`_ for more information.
``now`` ``now``
Display the date, formatted according to the given string. Display the date, formatted according to the given string.
Uses the same format as PHP's ``date()`` function; see http://php.net/date Uses the same format as PHP's ``date()`` function; see http://php.net/date
for all the possible values. for all the possible values.
Sample usage:: Sample usage::
It is {% now "jS F Y H:i" %} It is {% now "jS F Y H:i" %}
``regroup`` ``regroup``
Regroup a list of alike objects by a common attribute. Regroup a list of alike objects by a common attribute.
This complex tag is best illustrated by use of an example: say that ``people`` 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 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: ``gender`` attributes, and you'd like to display a list that looks like:
* Male: * Male:
* George Bush * George Bush
* Bill Clinton * Bill Clinton
@ -462,9 +462,9 @@ Built-in tag reference
* Colendeeza Rice * Colendeeza Rice
* Unknown: * Unknown:
* Janet Reno * Janet Reno
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>
{% for group in grouped %} {% for group in grouped %}
@ -476,42 +476,42 @@ Built-in tag reference
</ul> </ul>
{% 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. Output the contents of a given file into the page.
Like a simple "include" tag, the ``ssi`` tag includes the contents Like a simple "include" tag, the ``ssi`` tag includes the contents
of another file -- which must be specified using an absolute page -- of another file -- which must be specified using an absolute page --
in the current page:: 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, with the current context:: file are evaluated as template code, with the current context::
{% ssi /home/html/ljworld.com/includes/right_generic.html parsed %} {% ssi /home/html/ljworld.com/includes/right_generic.html parsed %}
``templatetag`` ``templatetag``
Output one of the bits used to compose template tags. Output one of the bits used to compose template tags.
Since the template system has no concept of "escaping", to display one of the 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. bits used in template tags, you must use the ``{% templatetag %}`` tag.
The argument tells which template bit to output: The argument tells which template bit to output:
================== ======= ================== =======
Argument Outputs Argument Outputs
================== ======= ================== =======
@ -520,15 +520,15 @@ Built-in tag reference
``openvariable`` ``{{`` ``openvariable`` ``{{``
``closevariable`` ``}}`` ``closevariable`` ``}}``
================== ======= ================== =======
``widthratio`` ``widthratio``
For creating bar charts and such, this tag calculates the ratio of a given value 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. to a maximum value, and then applies that ratio to a constant.
For example:: 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).
@ -538,152 +538,152 @@ Built-in filter reference
``add`` ``add``
Adds the arg to the value Adds the arg to the value
``addslashes`` ``addslashes``
Adds slashes - useful for passing strings to JavaScript, for example. Adds slashes - useful for passing strings to JavaScript, for example.
``capfirst`` ``capfirst``
Capitalizes the first character of the value Capitalizes the first character of the value
``center`` ``center``
Centers the value in a field of a given width Centers the value in a field of a given width
``cut`` ``cut``
Removes all values of arg from the given string Removes all values of arg from the given string
``date`` ``date``
Formats a date according to the given format (same as the ``now`` tag) Formats a date according to the given format (same as the ``now`` tag)
``default`` ``default``
If value is unavailable, use given default If value is unavailable, use given default
``dictsort`` ``dictsort``
Takes a list of dicts, returns that list sorted by the property given in the Takes a list of dicts, returns that list sorted by the property given in the
argument. argument.
``dictsortreversed`` ``dictsortreversed``
Takes a list of dicts, returns that list sorted in reverse order by the property Takes a list of dicts, returns that list sorted in reverse order by the property
given in the argument. given in the argument.
``divisibleby`` ``divisibleby``
Returns true if the value is divisible by the argument Returns true if the value is divisible by the argument
``escape`` ``escape``
Escapes a string's HTML Escapes a string's HTML
``filesizeformat`` ``filesizeformat``
Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102 Format the value like a 'human-readable' file size (i.e. 13 KB, 4.1 MB, 102
bytes, etc). bytes, etc).
``first`` ``first``
Returns the first item in a list Returns the first item in a list
``fix_ampersands`` ``fix_ampersands``
Replaces ampersands with ``&amp;`` entities Replaces ampersands with ``&amp;`` entities
``floatformat`` ``floatformat``
Displays a floating point number as 34.2 (with one decimal places) - but Displays a floating point number as 34.2 (with one decimal places) - but
only if there's a point to be displayed only if there's a point to be displayed
``get_digit`` ``get_digit``
Given a whole number, returns the requested digit of it, where 1 is the 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 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, 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. or if argument is less than 1). Otherwise, output is always an integer.
``join`` ``join``
Joins a list with a string, like Python's ``str.join(list)`` Joins a list with a string, like Python's ``str.join(list)``
``length`` ``length``
Returns the length of the value - useful for lists Returns the length of the value - useful for lists
``length_is`` ``length_is``
Returns a boolean of whether the value's length is the argument Returns a boolean of whether the value's length is the argument
``linebreaks`` ``linebreaks``
Converts newlines into <p> and <br />s Converts newlines into <p> and <br />s
``linebreaksbr`` ``linebreaksbr``
Converts newlines into <br />s Converts newlines into <br />s
``linenumbers`` ``linenumbers``
Displays text with line numbers Displays text with line numbers
``ljust`` ``ljust``
Left-aligns the value in a field of a given width Left-aligns the value in a field of a given width
**Argument:** field size **Argument:** field size
``lower`` ``lower``
Converts a string into all lowercase Converts a string into all lowercase
``make_list`` ``make_list``
Returns the value turned into a list. For an integer, it's a list of 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. digits. For a string, it's a list of characters.
``phone2numeric`` ``phone2numeric``
Takes a phone number and converts it in to its numerical equivalent Takes a phone number and converts it in to its numerical equivalent
``pluralize`` ``pluralize``
Returns 's' if the value is not 1, for '1 vote' vs. '2 votes' Returns 's' if the value is not 1, for '1 vote' vs. '2 votes'
``pprint`` ``pprint``
A wrapper around pprint.pprint -- for debugging, really A wrapper around pprint.pprint -- for debugging, really
``random`` ``random``
Returns a random item from the list Returns a random item from the list
``removetags`` ``removetags``
Removes a space separated list of [X]HTML tags from the output Removes a space separated list of [X]HTML tags from the output
``rjust`` ``rjust``
Right-aligns the value in a field of a given width Right-aligns the value in a field of a given width
**Argument:** field size **Argument:** field size
``slice`` ``slice``
Returns a slice of the list. Returns a slice of the list.
Uses the same syntax as Python's list slicing; see Uses the same syntax as Python's list slicing; see
http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice http://diveintopython.org/native_data_types/lists.html#odbchelper.list.slice
for an introduction. for an introduction.
``slugify`` ``slugify``
Converts to lowercase, removes non-alpha chars and converts spaces to hyphens Converts to lowercase, removes non-alpha chars and converts spaces to hyphens
``stringformat`` ``stringformat``
Formats the variable according to the argument, a string formatting specifier. Formats the variable according to the argument, a string formatting specifier.
This specifier uses Python string formating syntax, with the exception that This specifier uses Python string formating syntax, with the exception that
the leading "%" is dropped. the leading "%" is dropped.
See http://docs.python.org/lib/typesseq-strings.html for documentation See http://docs.python.org/lib/typesseq-strings.html for documentation
of Python string formatting of Python string formatting
``striptags`` ``striptags``
Strips all [X]HTML tags Strips all [X]HTML tags
``time`` ``time``
Formats a time according to the given format (same as the ``now`` tag). Formats a time according to the given format (same as the ``now`` tag).
``timesince`` ``timesince``
Formats a date as the time since that date (i.e. "4 days, 6 hours") Formats a date as the time since that date (i.e. "4 days, 6 hours")
``title`` ``title``
Converts a string into titlecase Converts a string into titlecase
``truncatewords`` ``truncatewords``
Truncates a string after a certain number of words Truncates a string after a certain number of words
**Argument:** Number of words to truncate after **Argument:** Number of words to truncate after
``unordered_list`` ``unordered_list``
Recursively takes a self-nested list and returns an HTML unordered list -- Recursively takes a self-nested list and returns an HTML unordered list --
WITHOUT opening and closing <ul> tags. WITHOUT opening and closing <ul> tags.
The list is assumed to be in the proper format. For example, if ``var`` contains The list is assumed to be in the proper format. For example, if ``var`` contains
``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``, ``['States', [['Kansas', [['Lawrence', []], ['Topeka', []]]], ['Illinois', []]]]``,
then ``{{ var|unordered_list }}`` would return:: then ``{{ var|unordered_list }}`` would return::
<li>States <li>States
<ul> <ul>
<li>Kansas <li>Kansas
@ -695,33 +695,33 @@ Built-in filter reference
<li>Illinois</li> <li>Illinois</li>
</ul> </ul>
</li> </li>
``upper`` ``upper``
Converts a string into all uppercase Converts a string into all uppercase
``urlencode`` ``urlencode``
Escapes a value for use in a URL Escapes a value for use in a URL
``urlize`` ``urlize``
Converts URLs in plain text into clickable links Converts URLs in plain text into clickable links
``urlizetrunc`` ``urlizetrunc``
Converts URLs into clickable links, truncating URLs to the given character limit Converts URLs into clickable links, truncating URLs to the given character limit
**Argument:** Length to truncate URLs to. **Argument:** Length to truncate URLs to.
``wordcount`` ``wordcount``
Returns the number of words Returns the number of words
``wordwrap`` ``wordwrap``
Wraps words at specified line length Wraps words at specified line length
**Argument:** number of words to wrap the text at. **Argument:** number of words to wrap the text at.
``yesno`` ``yesno``
Given a string mapping values for true, false and (optionally) None, Given a string mapping values for true, false and (optionally) None,
returns one of those strings according to the value: returns one of those strings according to the value:
========== ====================== ================================== ========== ====================== ==================================
Value Argument Outputs Value Argument Outputs
========== ====================== ================================== ========== ====================== ==================================