[Django]-Django 1.6 – How to short the text displayed into a template?

3👍

Have you tried the template tag truncatechars?

{{ value|truncatechars:[number to truncate chars after] }}

Check out how you’d handle the (more) part here:

If you actually wanted a link to persist and not just hover, you would probably want to use javascript to manipulate your DOM.

0👍

Make sure 15 (this is arbitrary) is greater than the number you’re slicing by:

{% if value|length > 15 %}
    {{ value|slice:"-6" }}<a href="#">(more)</a>
{% else %}
    {{ value }}
{% endif %}

Leave a comment