djangosnippets.org: Latest snippets tagged with 'words'https://djangosnippets.org/tags/words/2009-05-20T16:37:15.974511-05:00Word-boundary-aware string truncation template filter
2009-05-20T16:37:15.974511-05:00joshohttps://djangosnippets.org/snippets/1516/<p>This is a custom template filter that allows you to truncate a string to a maximum of num characters, but respecting word boundaries. So, for example, if <code>string = "This is a test string."</code>, then <code>{{ string|truncatechars:12 }}</code> would give you "This is a..." instead of "This is a …</p>
Freely redistributableTruncate string after a given number of chars keeping whole words
2008-12-23T06:27:07.712404-06:00rixhttps://djangosnippets.org/snippets/1259/<p>Truncates a string after a given length, keeping the last word complete.</p>
<p>This filter is more precise than the default <code>truncatewords</code> filter.</p>
<p>Words length vary too much, 10 words may result in 40 or 70 characters, so cutting by character count makes more sense.</p>
<p>There is a <a href="http://ricobl.wordpress.com/2008/12/23/templates-django-filtro-truncatewords-melhorado/">blog post</a> about …</p>
Freely redistributable