Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide missing examples from the built-in templatetags and filters #19244 #509

Merged
merged 2 commits into from
Nov 13, 2012
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions docs/ref/templates/builtins.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ comment

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

csrf_token
Expand Down Expand Up @@ -947,6 +954,10 @@ Argument Outputs
``closecomment`` ``#}``
================== =======

Sample usage::

{% templatetag openblock %} url 'entry_list' {% templatetag closeblock %}

.. templatetag:: url

url
Expand Down Expand Up @@ -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
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

escapejs
Expand Down Expand Up @@ -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
the :tfilter:`escape` filter.

For example, if you want to catch the ``<p>`` HTML elements created by
the :tfilter:`linebreaks` filter::

{% autoescape off %}
{{ body|linebreaks|force_escape }}
{% endautoescape %}

.. templatefilter:: get_digit

get_digit
Expand Down Expand Up @@ -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*).
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,
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.

Expand All @@ -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
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.

Expand Down