mirror of
https://github.com/django/django.git
synced 2025-08-04 10:59:45 +00:00
Fixed #19496 -- Added truncatechars_html filter.
Thanks esevece for the suggestion and Nick Sandford and Martin Warne for the inital work on the patch.
This commit is contained in:
parent
390001ce52
commit
f94f466cd3
5 changed files with 93 additions and 23 deletions
|
@ -2172,6 +2172,26 @@ For example::
|
|||
|
||||
If ``value`` is ``"Joel is a slug"``, the output will be ``"Joel i..."``.
|
||||
|
||||
.. templatefilter:: truncatechars_html
|
||||
|
||||
truncatechars_html
|
||||
^^^^^^^^^^^^^^^^^^
|
||||
|
||||
.. versionadded:: 1.7
|
||||
|
||||
Similar to :tfilter:`truncatechars`, except that it is aware of HTML tags. Any
|
||||
tags that are opened in the string and not closed before the truncation point
|
||||
are closed immediately after the truncation.
|
||||
|
||||
For example::
|
||||
|
||||
{{ value|truncatechars_html:9 }}
|
||||
|
||||
If ``value`` is ``"<p>Joel is a slug</p>"``, the output will be
|
||||
``"<p>Joel i...</p>"``.
|
||||
|
||||
Newlines in the HTML content will be preserved.
|
||||
|
||||
.. templatefilter:: truncatewords
|
||||
|
||||
truncatewords
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue