---
title: truncatewords
description: "Shorten text to a word limit."
---

# truncatewords

Shorten text to a word limit.

## Syntax

```knap
{{ value | truncatewords:20 }}
{{ value | truncatewords:(20, "...") }}
```

## Usage

- The required first parameter is a non-negative word limit.
- The suffix defaults to `…`. Pass a second parameter to replace it, or `""` to omit it.
- The suffix is appended after the requested number of words.
- Whitespace within the retained text is preserved.
- For arrays and objects, including serialized collections from another filter, string values are formatted recursively while keys and non-string values are preserved.

## Examples

### Default suffix

```json title="Data"
{
  "text": "A concise introduction to Knap"
}
```

```knap title="Template"
{{ text | truncatewords:3 }}
```

```md title="Output"
A concise introduction…
```

### No suffix

```json title="Data"
{
  "text": "A concise introduction to Knap"
}
```

```knap title="Template"
{{ text | truncatewords:(3, "") }}
```

```md title="Output"
A concise introduction
```

## Related filters

- [truncate](/filters/truncate)
