With the truncate modifier, a text can be truncated to a specific number of characters or whole words after a configurable number of characters.

truncate

{{$text|truncate:10}}

Arguments

ArgumentDescription
1An integer indicating the length at which the text should be truncated.
2The character(s) to be added after the truncated string, default is empty.
3A boolean value to indicate whether to truncate at the exact character position (true) or on whole words (false). The default value is false.
4A boolean value to apply the truncation at the end of the text (false) or to break in the middle of the text (true). The default value is false.

Examples

truncate examples

{{$articleTitle = 'Two Sisters Reunite after Eighteen Years at Checkout Counter.'}}

{{$articleTitle}}
{{$articleTitle|truncate}}
{{$articleTitle|truncate:30}}
{{$articleTitle|truncate:30:""}}
{{$articleTitle|truncate:30:"---"}}
{{$articleTitle|truncate:30:"":true}}
{{$articleTitle|truncate:30:"...":true}}
{{$articleTitle|truncate:30:'..':true:true}}

Output:
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after Eighteen Years at Checkout Counter.
Two Sisters Reunite after...
Two Sisters Reunite after
Two Sisters Reunite after---
Two Sisters Reunite after Eigh
Two Sisters Reunite after E...
Two Sisters Re..ckout Counter.