mirror of
https://github.com/kemko/liquid.git
synced 2026-01-06 18:25:41 +03:00
1.3 KiB
1.3 KiB
title, description
| title | description |
|---|---|
| truncatewords | Liquid filter that truncates a string to the given number of words. |
Shortens a string down to the number of words passed as the argument. If the specified number of words is less than the number of words in the string, an ellipsis (...) is appended to the string.
Input
```liquid {% raw %} {{ "Ground control to Major Tom." | truncatewords: 3 }} {% endraw %} ```Output
```text {{ "Ground control to Major Tom." | truncatewords: 3 }} ```Custom ellipsis
truncatewords takes an optional second parameter that specifies the sequence of characters to be appended to the truncated string. By default this is an ellipsis (...), but you can specify a different sequence.
Input
{% raw %} ``` liquid {{ "Ground control to Major Tom." | truncatewords: 3, "--" }} ``` {% endraw %}Output
``` text {{ "Ground control to Major Tom." | truncatewords: 3, "--" }} ```No ellipsis
You can avoid showing trailing characters by passing a blank string as the second parameter:
Input
{% raw %} ``` liquid {{ "Ground control to Major Tom." | truncatewords: 3, "" }} ``` {% endraw %}Output
``` text {{ "Ground control to Major Tom." | truncatewords: 3, "" }} ```