I've used truncatechars
but if text contains a html tag, it will show the tag for me.
{{content.text|safe|truncatechars:140}}
for example displays something like this:
<p>hi</p>
I want to remove p
tag.
Updated along with question:
To completely remove the tags before truncating, use:
{{ content.text|striptags|truncatechars:140 }}
Original answer:
To ensure the tags are broken correctly, you'll want to use the truncatechars_html
template filter.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With