Added examples for comment, templatetag, escape, force_escape, timesince, and timeuntil

This commit is contained in:
Daniel Greenfeld 2012-11-08 16:32:16 -08:00
parent 9942adac17
commit 1db5d88273
1 changed files with 30 additions and 2 deletions

View File

@ -53,6 +53,13 @@ comment
Ignores everything between ``{% comment %}`` and ``{% endcomment %}``. Ignores everything between ``{% comment %}`` and ``{% endcomment %}``.
Sample usage::
<p>Rendered text with {{ pub_date|date:"c" }}</p>
{% comment %}
<p>Commented out text with {{ create_date|date:"c" }}</p>
{% endcomment %}
.. templatetag:: csrf_token .. templatetag:: csrf_token
csrf_token csrf_token
@ -947,6 +954,10 @@ Argument Outputs
``closecomment`` ``#}`` ``closecomment`` ``#}``
================== ======= ================== =======
Sample usage::
{% templatetag openblock %} url 'entry_list' {% templatetag closeblock %}
.. templatetag:: url .. templatetag:: url
url url
@ -1409,6 +1420,12 @@ applied to the result will only result in one round of escaping being done. So
it is safe to use this function even in auto-escaping environments. If you want it is safe to use this function even in auto-escaping environments. If you want
multiple escaping passes to be applied, use the :tfilter:`force_escape` filter. multiple escaping passes to be applied, use the :tfilter:`force_escape` filter.
For example, you can apply ``escape`` to fields when :ttag:`autoescape` is off::
{% autoescape off %}
{{ title|escape }}
{% endautoescape %}
.. templatefilter:: escapejs .. templatefilter:: escapejs
escapejs escapejs
@ -1542,6 +1559,13 @@ string. This is useful in the rare cases where you need multiple escaping or
want to apply other filters to the escaped results. Normally, you want to use want to apply other filters to the escaped results. Normally, you want to use
the :tfilter:`escape` filter. the :tfilter:`escape` filter.
For example, if you want to catch the ``<paragraph>`` HTML elements created by
the :tfilter:`linebreaks` filter::
{% autoescape off %}
{{ body|linebreaks|force_escape }}
{% endautoescape %}
.. templatefilter:: get_digit .. templatefilter:: get_digit
get_digit get_digit
@ -1979,7 +2003,9 @@ 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*). the comparison point (without the argument, the comparison point is *now*).
For example, if ``blog_date`` is a date instance representing midnight on 1 For example, if ``blog_date`` is a date instance representing midnight on 1
June 2006, and ``comment_date`` is a date instance for 08:00 on 1 June 2006, June 2006, and ``comment_date`` is a date instance for 08:00 on 1 June 2006,
then ``{{ blog_date|timesince:comment_date }}`` would return "8 hours". then the following would return "8 hours"::
{{ blog_date|timesince:comment_date }}
Comparing offset-naive and offset-aware datetimes will return an empty string. Comparing offset-naive and offset-aware datetimes will return an empty string.
@ -1998,7 +2024,9 @@ given date or datetime. For example, if today is 1 June 2006 and
Takes an optional argument that is a variable containing the date to use as Takes an optional argument that is a variable containing the date to use as
the comparison point (instead of *now*). If ``from_date`` contains 22 June the comparison point (instead of *now*). If ``from_date`` contains 22 June
2006, then ``{{ conference_date|timeuntil:from_date }}`` will return "1 week". 2006, then the following will return "1 week"::
{{ conference_date|timeuntil:from_date }}
Comparing offset-naive and offset-aware datetimes will return an empty string. Comparing offset-naive and offset-aware datetimes will return an empty string.