Dynamic Length Truncate Tag
Almost a year ago I wrote about Simple Character Truncate Filter And Dot Dot Dot Variant which was a basic string truncate written as a Django filter. It worked great until I needed to dynamically specify the length. Turns out filters are not good at resolving context variables (at least I dont know of a simple way). So to follow up the success of the original filter I’ve created a dynamic version implemented as a tag. Now you can specify any string and length (as a variable) and it will be truncated to that length in place.
Code
The implementation for the new tag only handles context variables, if you are hard coding the length just use a slice filter or the Simple Character Truncate Filter And Dot Dot Dot Variant instead.
dynamic_truncate_tag.py
sample.html
-
Rowena
-
Doug
-
SmileyChris

![Recommend [AwareLabs]](http://s3.amazonaws.com/arkayne-media/img/badge/logo-recommend-badge-medium.png)