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 letters by trbs 4 years, 10 months ago
- truncate by alfor 4 years, 10 months ago
- Word-boundary-aware string truncation template filter by josho 2 years, 8 months ago
- Precise truncate chars filter by davmuz 2 weeks, 6 days ago
- truncatechars filter by semente 2 years, 5 months ago
Comments