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
CALIThe 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.
Filters
- abs
- append
- at_least
- at_most
- capitalize
- ceil
- compact
- concat
- date
- default
- divided_by
- downcase
- escape
- escape_once
- first
- floor
- join
- last
- lstrip
- map
- minus
- modulo
- newline_to_br
- plus
- prepend
- remove
- remove_first
- replace
- replace_first
- reverse
- round
- rstrip
- size
- slice
- sort
- sort_natural
- split
- strip
- strip_html
- strip_newlines
- times
- truncate
- truncatewords
- uniq
- upcase
- url_decode
- url_encode
- where
- raw
- slugify
- number_format
