« Digg For Django Is Here | Home | Installing Django And MySQL On MacBook Air Or OS X »
Dynamic Length Truncate Tag
By Paul Kenjora | April 2, 2008
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.