Guide
Trimming & Truncation
Wordsmith provides several helpful methods for trimming text content.
Wordsmith’s trimming & truncation methods include:
Truncation
chop
Chops content down to the given limit
of paragraphs
, words
, or characters
.
Will optionally append
a string to the end of the chopped content.
Skips over allowedTags
as instructed.
unit
('p'
) — the unit of content to truncate'paragraphs'
,'p'
'words'
,'w'
'characters'
,'c'
limit
(1
) — the number of units to allowappend
(''
) — a string that will be added to the end of the truncated textallowedTags
(null
) — a string indicating what HTML tags are allowed to stay in the content before trimming; all other HTML will be striped. (When you usechop
with theparagraphs
unit,'<p>'
tags are maintained automatically.)
{% set text %} |
hacksaw
An alias for chop
.
Provided for backwards compatibility, so that Wordsmith can be a drop-in replacement for the Hacksaw plugin.
Trimming
trim
Returns a string with whitespace removed from the start and end of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
chars
— characters to strip instead of the defaults
{{ ' fòôbàř ' }} |
trimLeft
Returns a string with whitespace removed from the start of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
chars
— characters to strip instead of the defaults
{{ ' fòôbàř ' }} |
trimRight
Returns a string with whitespace removed from the end of the string. Supports the removal of unicode whitespace. Accepts an optional string of characters to strip instead of the defaults.
chars
— characters to strip instead of the defaults
{{ ' fòôbàř ' }} |