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: ', ' }}
{{ collection.title | slice: 0 }}
{{ collection.title | slice: 0, 5 }}
{{ collection.all_tags | slice: 1, 2 | join: ', ' }}
{
"collection": {
"all_tags": [
"Burning",
"dried",
"extra-potent",
"extracts",
"fresh",
"healing",
"ingredients",
"music",
"plant",
"Salty",
"supplies"
],
"title": "Products"
}
}
Output
P
Produ
dried, extra-potent
Anchor to Negative index
Negative index
You can supply a negative index which will count from the end of the string.
{{ collection.title | slice: -3, 3 }}
{{ collection.title | slice: -3, 3 }}
{
"collection": {
"title": "Products"
}
}
Output
cts
Was this page helpful?