1 2 3 4 5 6 7 8 9 10 11 12 13 | @register.filter
def trunc( string, number, dots='...'):
"""
truncate the {string} to {number} characters
print {dots} on the end if truncated
usage: {{ "some text to be truncated"|trunc:6 }}
results: some te...
"""
if not isinstance(string, str): string = str(string)
if len(string) <= number:
return string
return string[0:number]+dots
|
More like this
- truncate by alfor 6 years, 2 months ago
- Truncate string after a given number of chars keeping whole words by rix 4 years, 5 months ago
- Truncate HTML without breaking tags by olau 4 years, 1 month ago
- truncatechars filter by semente 3 years, 9 months ago
- truncatehtml_at_word by zakj 4 years, 7 months ago
Comments