Files
liquid/filters/slice.md
2016-04-02 18:46:32 -04:00

1.0 KiB

title
title
slice

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

String indices are numbered starting from 0.

Input

```liquid {% raw %} {{ "Liquid" | slice: 0 }} {% endraw %} ```

Output

```text {{ "Liquid" | slice: 0 }} ```

Input

```liquid {% raw %} {{ "Liquid" | slice: 2 }} {% endraw %} ```

Output

```text {{ "Liquid" | slice: 2 }} ```

Input

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

Output

```text {{ "Liquid" | slice: 2, 5 }} ```

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

Input

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

Output

```text {{ "Liquid" | slice: -3, 2 }} ```