slice

Extract a substring or array slice beginning at an offset index for a specified length.

Syntax

{{ string_or_array | slice: start, length }}

Example

{% assign code = "CALIFORNIA" %}{{ code | slice: 0, 4 }}

Output

CALI

The slice filter extracts a subset of characters from a string or a range of elements from an array, beginning at a zero-based offset for an optional specified length.

On programmatic landing pages, slice truncates long postal identifiers or extracts state prefixes from composite location keys. For example: {{ row.tax_id | slice: 0, 3 }}-*** privacy code. It is also used to pull the leading characters of customer reviews for compact preview snippets in sidebar cards.

Try this syntax in the editor.