djangosnippets.org: Latest snippets tagged with 'truncatewords'https://djangosnippets.org/tags/truncatewords/2012-01-20T05:06:28.675440-06:00Precise truncate chars filter
2012-01-20T05:06:28.675440-06:00davmuzhttps://djangosnippets.org/snippets/2653/<p>Template filter that truncates the text when it exceeds a certain number of characters.
It deletes the last word only if partial.
Adds '...' at the end of the text, only if truncated.</p>
<p>Examples (text == 'Lorem ipsum dolor sit amet', len(text) == 26)</p>
<pre><code>{{ text|truncatewords_by_chars:30 }}
'Lorem ipsum dolor …</code></pre>
Freely redistributabletruncatechars filter
2009-09-03T11:38:35.957613-05:00sementehttps://djangosnippets.org/snippets/1715/<p>Truncates a string after a certain number of chars.</p>
<p>Question:</p>
<blockquote>
<p><em>Why don't you use the built-in filter slice?</em></p>
</blockquote>
<p>I need the "three points" (...) only when it really truncates.</p>
Freely redistributable