I am on Google App Eninge with Django template.
I want to truncate string after a given number of chars, for example,
if a string (a title of a post) is too long, “This is a long long long long title”, I want to display the first few words, like this: “This is a long long …”
I have found some Django snippets here: http://djangosnippets.org/snippets/1259/ http://djangosnippets.org/snippets/763/
I want to know:
-
If there is a simpler solution in Google App Engine python?
-
How can I use this snippet http://djangosnippets.org/snippets/1259/
in App Engine? I believe messing source code is not a good idea.
I need to truncate the string in Django Template, not in python source code. Something like this: {{ string|truncatesmart:50 }}
From your description of the problem, it appears it’s a situation which has already been specifically addressed by pure CSS. Take a look at the
text-overflow:ellipsisproperty, which truncates a piece of text to fit in a desired width and puts a trailing ellipsis (…) like you mentioned. I hope that’ll be a far simpler solution here and you won’t have to ‘reinvent the wheel’.