/Truncate

A simple Craft CMS plugin/Twig filter.

Primary LanguagePHP

Truncate

A simple Craft CMS plugin/Twig filter.

Usage

{{ entry.body | truncate('words', '150', '...', true) }}

Params

  • Unit: words or chars. Defaults to chars.
  • Limit: Defaults to 150.
  • Ending: Defaults to an empty string.
  • StripHTML: Removes all HTML tags. Defaults to false

Note

The native Twig filters split, join, and slice can be used to achieve a similar result:

{% set words = "these are words"|split(" ")|slice(1, 2)|join(" ") %}
{{ words }}