Skip to content

Slice ​

Returns a substring, starting at an index. The first character has the index 0. A negative index counts from the end of the string. The second argument sets the length of the substring. Without it, the substring continues to the end. On an array, the filter returns the items in this range.

liquid
{{ string | slice: index, length }}

Example ​

liquid
{{ 'YouCan' | slice: 0, 3 }}
{{ 'YouCan' | slice: 3 }}
{{ 'YouCan' | slice: -3, 2 }}

Output

html
You
Can
Ca