Skip to main content

slice

string | slice
returns string

Returns a substring or series of array items, starting at a given 0-based index.

By default, the substring has a length of one character, and the array series has one array item. However, you can provide a second parameter to specify the number of characters or array items.

{{ collection.title | slice: 0 }}
{{ collection.title | slice: 0, 5 }}

{{ collection.all_tags | slice: 1, 2 | join: ', ' }}

Output

P
Produ

dried, extra-potent

You can supply a negative index which will count from the end of the string.

{{ collection.title | slice: -3, 3 }}

Output

cts
Was this page helpful?