truncatewords

truncatewords

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

{{ "Ground control to Major Tom." | truncatewords: 3 }}

Output

Ground control to...

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

{{ "Ground control to Major Tom." | truncatewords: 3, "--" }}

Output

Ground control to--

No ellipsis

You can avoid showing trailing characters by passing a blank string as the second parameter:

Input

{{ "Ground control to Major Tom." | truncatewords: 3, "" }}

Output

Ground control to

© 2005, 2006 Tobias Luetke
Licensed under the MIT License.
https://shopify.github.io/liquid/filters/truncatewords/

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部