mirror of
https://github.com/kemko/liquid.git
synced 2026-01-03 16:55:40 +03:00
1.1 KiB
1.1 KiB
title, description
| title | description |
|---|---|
| slice | Liquid filter that returns a substring from a given position in a string. |
Returns a substring of 1 character beginning at the index specified by the first argument. 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 argument 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 }} ```