AdonisJS v6 is here. Learn more in our release blog post.

truncate

The view helper truncates a given string value by the number of characters. For example:

{{
truncate(
'This is a very long sentence that i would like to be shortened',
18
)
}}
<!-- Output: This is a very long... -->

The truncate method doesn't chop the words in between and let them get completed. However, you can turn off this behavior by setting completeWords option to false.

{{
truncate(
'This is a very long sentence that i would like to be shortened',
18,
{ completeWords: false }
)
}}
<!-- Output: This is a very lon... -->

Also, you can define a custom suffix for the truncated string.

{{
truncate(
'This is a very long sentence that i would like to be shortened',
18,
{ suffix: ' [Read more]' }
)
}}
<!-- Output: This is a very long [Read more] -->