Login

Tag "truncatewords"

Snippet List

Precise truncate chars filter

Template filter that truncates the text when it exceeds a certain number of characters. It deletes the last word only if partial. Adds '...' at the end of the text, only if truncated. Examples (text == 'Lorem ipsum dolor sit amet', len(text) == 26) {{ text|truncatewords_by_chars:30 }} 'Lorem ipsum dolor sit amet' {{ text|truncatewords_by_chars:25 }} 'Lorem ipsum dolor sit...' {{ text|truncatewords_by_chars:21 }} 'Lorem ipsum dolor sit...' {{ text|truncatewords_by_chars:20 }} 'Lorem ipsum dolor...' By Davide Muzzarelli

  • filter
  • template-filter
  • truncate
  • truncatewords
Read More

truncatechars filter

Truncates a string after a certain number of chars. Question: > *Why don't you use the built-in filter slice?* I need the "three points" (...) only when it really truncates.

  • template
  • filter
  • truncatewords
Read More

2 snippets posted so far.