A simple Craft CMS plugin/Twig filter.
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
twigextensions
README.md
TruncatePlugin.php

README.md

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 }}