Files
liquid/filters/slice.md
2015-12-13 22:39:26 -05:00

779 B

title
title
slice

slice returns a substring of 1 character beginning at the index specified by the parameter passed in. An optional second parameter specifies the length of the substring to be returned.

String indices are numbered starting from 0.

{% raw %}
{{ "Liquid" | slice: 0 }}
{% endraw %}
{{ "Liquid" | slice: 0 }}
{% raw %}
{{ "Liquid" | slice: 2 }}
{% endraw %}
{{ "Liquid" | slice: 2 }}
{% raw %}
{{ "Liquid" | slice: 2, 5 }}
{% endraw %}
{{ "Liquid" | slice: 2, 5 }}

If the first parameter is a negative number, the indices are counted from the end of the string:

{% raw %}
{{ "Liquid" | slice: -3, 2 }}
{% endraw %}
{{ "Liquid" | slice: -3, 2 }}