In the core symfony / twig do not have a simple truncate-text-function, like substr() in PHP. Therefor you have to activate the Twig-Text-Extension:
1 2 3 4 5 6 |
// app/config/config.yml services: twig.extension.text: class: Twig_Extensions_Extension_Text tags: - { name: twig.extension } |
Now you can easily truncate as you like:
1 |
{{ var.long_description | truncate(50) }} |
If you want to preserve whole words, you have to set the 2nd parameter:
1 |
{{ var.long_description | truncate(50, true) }} |
With the 3rd parameter you can override the default seperator ‘…':
1 |
{{ var.long_description | truncate(50, true, '.......') }} |
Thanks Scott