Articles in this section

truncateWords helper

Shortens a string to a set number of words and optionally appends a suffix. This is useful when you need to limit text length in fields, summaries, or previews.

Usage

{{truncateWords string limit suffix}}
  • string (required): input string

  • limit: number of words to keep

  • suffix (optional): suffix to append (defaults to ...)

Examples

  1. Truncate a description to different word counts

    {{truncateWords record.description 1}}
    {{truncateWords record.description 2}}
    {{truncateWords record.description 3}}
    

    Input:

    { "record": { "description": "foo bar baz" } }
    

    Output:

    foo…
    foo bar…
    foo bar baz
    
  2. Custom suffix

    {{truncateWords record.notes 2 "--more"}}
    

    Input:

    { "record": { "notes": "Integration setup requires testing" } }
    

    Output:

    Integration setup--more
    
  3. Truncate to zero words (returns only suffix)

    {{truncateWords record.description 0}}

    Input:

    { "record": { "description": "foo bar baz" } }

    Output:

Tip

  • Word boundaries are respected—truncation doesn’t cut off part of a word.

  • If the number of words in the input is less than or equal to the limit, the string is returned unchanged.

  • Use the suffix parameter to provide user-friendly cues, such as " (continued)" or "...".

  • limit is required and must be a non-negative integer. 0 returns only the suffix. Negative or non-numeric ⇒ empty result.