diff options
Diffstat (limited to 'docs/templates.txt')
| -rw-r--r-- | docs/templates.txt | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/docs/templates.txt b/docs/templates.txt index 4ba52b3263..0f0009b495 100644 --- a/docs/templates.txt +++ b/docs/templates.txt @@ -47,7 +47,7 @@ explained later in this document.:: JavaScript and CSV. You can use the template language for any text-based format. - Oh, and one more thing: Making humans edit XML is masochistic! + Oh, and one more thing: Making humans edit XML is sadistic! Variables ========= @@ -109,6 +109,21 @@ Some tags require beginning and ending tags (i.e. below describes all the built-in tags. You can create your own tags, if you know how to write Python code. +Comments +======== + +**New in Django development version** + +To comment-out part of a template, use the comment syntax: ``{# #}``. + +For example, this template would render as ``'hello'``:: + + {# greeting #}hello + +A comment can contain any template code, invalid or not. For example:: + + {# {% if foo %}bar{% else %} #} + Template inheritance ==================== @@ -141,6 +156,7 @@ It's easiest to understand template inheritance by starting with an example:: {% block content %}{% endblock %} </div> </body> + </html> This template, which we'll call ``base.html``, defines a simple HTML skeleton document that you might use for a simple two-column page. It's the job of @@ -196,6 +212,7 @@ like:: <p>This is my second entry.</p> </div> </body> + </html> Note that since the child template didn't define the ``sidebar`` block, the value from the parent template is used instead. Content within a ``{% block %}`` @@ -363,10 +380,15 @@ extends Signal that this template extends a parent template. -This tag may be used in two ways: ``{% extends "base.html" %}`` (with quotes) -uses the literal value "base.html" 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. +This tag can be used in two ways: + + * ``{% extends "base.html" %}`` (with quotes) uses the literal value + ``"base.html"`` as the name of the parent template to extend. + + * ``{% extends variable %}`` uses the value of ``variable``. If the variable + evaluates to a string, Django will use that string as the name of the + parent template. If the variable evaluates to a ``Template`` object, + Django will use that object as the parent template. See `Template inheritance`_ for more information. @@ -493,6 +515,11 @@ If you need to combine ``and`` and ``or`` to do advanced logic, just use nested {% endif %} {% endif %} +Multiple uses of the same logical operator are fine, as long as you use the +same operator. For example, this is valid:: + + {% if athlete_list or coach_list or parent_list or teacher_list %} + ifchanged ~~~~~~~~~ @@ -528,6 +555,11 @@ The arguments can be hard-coded strings, so the following is valid:: ... {% endifequal %} +It is only possible to compare an argument to template variables or strings. +You cannot check for equality with Python objects such as ``True`` or +``False``. If you need to test if something is true or false, use the ``if`` +and ``ifnot`` tags instead. + ifnotequal ~~~~~~~~~~ @@ -951,13 +983,13 @@ any string. pluralize ~~~~~~~~~ -Returns a plural suffix if the value is not 1. By default, this suffix is ``'s'``. +Returns a plural suffix if the value is not 1. By default, this suffix is ``'s'``. Example:: You have {{ num_messages }} message{{ num_messages|pluralize }}. -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. Example:: @@ -1039,7 +1071,7 @@ Formats a date as the time since that date (i.e. "4 days, 6 hours"). Takes an optional argument that is a variable containing the date to use as the comparison point (without the argument, the comparison point is *now*). For example, if ``blog_date`` is a date instance representing midnight on 1 -June 2006, and ``comment_date`` is a date instanace for 08:00 on 1 June 2006, +June 2006, and ``comment_date`` is a date instance for 08:00 on 1 June 2006, then ``{{ comment_date|timesince:blog_date }}`` would return "8 hours". timeuntil |
