slice - Liquid Filter Reference - 1.0.0

Filter Name slice
Group Arrays
Version 1.0.0

Description

Returns a substring of one character or series of array items beginning at the index specified by the first argument. An optional second argument specifies the length of the substring or number of array items to be returned.

Examples

{{ "Earthquake" | slice: 0 }}
E
{{ "Earthquake" | slice: 2 }}
r
{{ "Earthquake" | slice: 2, 5 }}
rthqu
Here the input value is an array:
{% assign an_array = "earth, water, air, fire" | split: ", " %}

{{ an_array | slice: 1, 2 }}
waterair
If the first argument is a negative number, the indices are counted from the end of the string:
{{ "Earthquake" | slice: -3, 2 }}
ak

Back to Filter List

Back to Liquid Reference for 1.0.0

 

 
Back to Documentation