Twig :: truncate

The truncate filter will cut off a string after a limit is reached.

Since

0.1.0

Usage

truncate(length = 30, preserve = false, separator = '...')

Parameters

  • length : int

    The amount of characters to truncate a string to

  • preserve : bool

    When set to true, the last word will be preserved

  • separator : string

    The set of character(s) that will be appended to the truncated string

Example Usage

Here's some sample usage.

<!-- "Hello..." -->
{{ "Hello World!" | truncate(5) }}

<!-- "Hello World!" -->
{{ "Hello World!" | truncate(7, true) }}

<!-- "Hello W??" -->
{{ "Hello World!" | truncate(7, false, '??') }}