Filters
This page contains definitions for all Mechanic-supported Liquid filters.
Filters that are unique to Mechanic (and not available in Shopify or on other platforms) are noted with an asterisk.
This page is a developer reference for Liquid filters supported by Mechanic. For an introduction to the concept of filters, see Filters.

Data filters

base64, decode_base64 *

Allows for converting between strings and their base64-encoded representations.
1
{% assign json_safe_image = image | base64 %}
2
{% assign original_image = json_safe_image | decode_base64 %}
Copied!

browser *

This filter converts a browser user agent string into an object that represents the browser itself. (This filter uses data from Browserscope to match user agents.
Code
Output
1
{% assign browser = "Mozilla/5.0 (iPhone; CPU iPhone OS 12_4 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) GSA/79.0.259819395 Mobile/16G77 Safari/604.1" | browser %}
2
​
3
{{ browser }}
4
​
5
name: {{ browser.name }}
6
​
7
version: {{ browser.version }}
8
major version: {{ browser.version.major }}
9
minor version: {{ browser.version.minor }}
10
​
11
os: {{ browser.os }}
12
os name: {{ browser.os.name }}
13
os version: {{ browser.os.version }}
14
os major version: {{ browser.os.version.major }}
15
os minor version: {{ browser.os.version.minor }}
16
​
17
device: {{ browser.device }}
18
device name: {{ browser.device.name }}
19
device brand: {{ browser.device.brand }}
20
device model: {{ browser.device.model }}
Copied!
1
Google 79.0.259819395
2
​
3
name: Google
4
​
5
version: 79.0.259819395<br>major version: 79<br>minor version: 0
6
​
7
os: iOS 12.4<br>os name: iOS<br>os version: 12.4<br>os major version: 12<br>os minor version: 4
8
​
9
device: iPhone<br>device name: iPhone<br>device brand: Apple<br>device model: iPhone
Copied!

csv, parse_csv *

Supports converting a two-dimensional array to a CSV string, and back again.
The parse_csv filter accepts a "headers" option; when set to true, this filter will interpret the first line of input as containing headers for the CSV table, and will return an array of hashes whose keys map to items in that header row.
csv
parse_csv
parse_csv with headers
1
{% capture two_dimensional_array_json %}
2
[
3
[
4
"Order Name",
5
"Order ID",
6
"Order Date"
7
],
8
[
9
"#1234",
10
1234567890,
11
"2021/03/23"
12
],
13
[
14
"#1235",
15
1234567891,
16
"2021/03/24"
17
]
18
]
19
{% endcapture %}
20
​
21
{% assign two_dimensional_array = two_dimensional_array_json | parse_json %}
22
​
23
{% assign csv_string = two_dimensional_array | csv %}
Copied!
1
{% comment %}
2
Note the dashes used in the capture/endcapture tags!
3
They make sure that we don't end up with blank lines
4
at the beginning and end of our CSV string.
5
{% endcomment %}
6
{% capture csv_string -%}
7
Order Name,Order ID,Order Date
8
#1234,1234567890,2021/03/23
9
#1235,1234567891,2021/03/24
10
{%- endcapture %}
11
​
12
{% assign csv_rows = csv_string | parse_csv %}
13
​
14
{% assign orders = array %}
15
{% for row in csv_rows %}
16
{% comment %}
17
Skip the header row
18
{% endcomment %}
19
{% if forloop.first %}
20
{% continue %}
21
{% endif %}
22
​
23
{% assign order = hash %}
24
{% assign order["name"] = row[0] %}
25
{% comment %}
26
We're using `times: 1` to convert our string ID to an integer
27
{% endcomment %}
28
{% assign order["id"] = row[1] | times: 1 %}
29
{% assign order["date"] = row[2] %}
30
​
31
{% assign orders[orders.size] = order %}
32
{% endfor %}
33
​
34
{{ orders | json }}
Copied!
1
{% comment %}
2
Note the dashes used in the capture/endcapture tags!
3
They make sure that we don't end up with blank lines
4
at the beginning and end of our CSV string.
5
{% endcomment %}
6
{% capture csv_string -%}
7
Order Name,Order ID,Order Date
8
#1234,1234567890,2021/03/23
9
#1235,1234567891,2021/03/24
10
{%- endcapture %}
11
​
12
{% comment %}
13
Note: the order ID is a string, in this resulting set of
14
hashes, not an integer!
15
{% endcomment %}
16
{% assign orders = csv_string | parse_csv: headers: true %}
17
​
18
{{ orders | json }}
19
{% comment %}
20
The result:
21
​
22
[
23
{
24
"Order Name": "#1234",
25
"Order ID": "1234567890",
26
"Order Date": "2021/03/23"
27
},
28
{
29
"Order Name": "#1235",
30
"Order ID": "1234567891",
31
"Order Date": "2021/03/24"
32
}
33
]
34
{% endcomment %}
Copied!

date, parse_date *

Mechanic's date filter is based on Shopify's date filter. Mechanic's implementation has all the functionality of Shopify's. It accepts a date format, using the same format as Ruby's strftime. (Sites like strfti.me offer convenient references for this format.) Under the hood, this filter uses ActiveSupport::TimeZone#strptime, and inherits its behavior with regard to missing upper components.

Choosing a timezone

Mechanic's date filter supports a tz option, which accepts a timezone name from the TZ database. If given, the resulting time string will be in the specified timezone. If this option is not provided, the store's local timezone will be used instead.
1
{{ "now" | date: "%Y-%m-%d %H:%M %z" }}
2
=> "2019-01-01 09:00 +0900"
3
​
4
{{ "now" | date: "%Y-%m-%d %H:%M %z", tz: "UTC" }}
5
=> "2019-01-01 00:00 +0000"
Copied!

Using the current time

This filter also accepts the special value "now", and values offset from now, as in "now + 5 days" or "now - 5 weeks". In this way, the filter supports simple date math. Note that durations are calculated using variable duration lengths, given the naturally varying length of specific days, weeks, months, and years, given DST and other calendar variances, all informed by the store's timezone. This math is backed by ActiveSupport::TimeWithZone#+. An example, quoting from that documentation: "a time + 24.hours will advance exactly 24 hours, while a time + 1.day will advance 23-25 hours, depending on the day".
1
{{ "now + 6 weeks" | date: "%Y-%m-%d %H:%M %z" }}
2
{{ "now + 3 months" | date: "%Y-%m-%d %H:%M %z" }}
3
{{ "now - 3 months" | date: "%Y-%m-%d %H:%M %z" }}
4
​
5
=> "2021-02-15 14:06 -0500"
6
=> "2021-04-04 14:06 -0400"
7
=> "2020-10-04 14:06 -0400"
Copied!

Parsing dates

Use parse_date to parse a date string, when its exact format is known. This filter is useful for strings that contain an ambiguous date value, like "01/01/01".
This filter returns an ISO8601 string, representing the parsed date value in the store's local timezone. If the supplied date string cannot be parsed successfully, the filter will return nil.
1
{{ "01-01-20" | parse_date: "%m-%d-%y" }}
2
=> "2020-01-01T00:00:00+11:00"
3
​
4
{{ "01-01-20" | parse_date: "%m-%d-%y" | date: "%Y-%m-%d" }}
5
=> "2020-01-01"
6
​
7
{{ "ab-cd-ef" | parse_date: "%m-%d-%y" }}
8
=> nil
Copied!

default

Returns either the input value, or – if the input is either nil, false, or an empty string "" – it returns its argument.
1
Howdy {{ order.shipping_address.first_name | default: "partner" }}
Copied!

gzip, gunzip *

These filters allow you to compress and decompress strings, using gzip compression.
In general, all strings passing through Mechanic must be UTF-8, and must ultimately be valid when represented as JSON. However, because gzip'd content may not be UTF-8, and because it may be important to preserve the original encoding, the gunzip filter supports a force_utf8: false option. Use this when you're certain the original encoding must be preserved, if you ultimately intend to pass along the string in a JSON-friendly representation. (For example, you might gunzip a value, and then use the base64 filter to represent it safely within JSON.)
1
{{ "testing" | gzip | gunzip }}
2
=> "testing"
3
​
4
{{ "hello world" | gzip | base64 }}
5
=> "H4sIABwbfl8AA8tIzcnJVyjPL8pJAQCFEUoNCwAAAA=="
6
​
7
{{ "H4sIANAafl8AA8tIzcnJVyjPL8pJAQCFEUoNCwAAAA==" | decode_base64: force_utf8: false | gunzip }}
8
=> "hello world"
9
​
10
{% assign base64_non_utf8_string = "H4sIACP1fV8AAyvPSCxRSMlPLVbILFHITU3MUyjJV0hKVXjUMKc4J7/8UcNcewAYP+lTIwAAAA==" %}
11
{{ base64_non_utf8_string | decode_base64: force_utf8: false | gunzip: force_utf8: false }}
12
=> (a string that is not UTF-8, and cannot be exported to JSON as-is)
13
​
14
{% assign base64_non_utf8_string = "H4sIACP1fV8AAyvPSCxRSMlPLVbILFHITU3MUyjJV0hKVXjUMKc4J7/8UcNcewAYP+lTIwAAAA==" %}
15
{{ base64_non_utf8_string | decode_base64: force_utf8: false | gunzip }}
16
=> "what does it mean to be β€œslow”?"
Copied!

graphql_arguments *

[todo]

img_url *

[todo]

json, parse_json, parse_jsonl *

Allows converting objects to their JSON representations, and parsing that JSON into hashes.
1
{% assign order_as_json = order | json }}
2
{% assign plain_order = order_as_json | parse_json %}
Copied!
The parse_jsonl filter can be used to parse a series of JSON strings, each on their own line, into an array of hashes. Useful when preparing stub data for bulk operations.
1
{% capture jsonl_string %}
2
{"id":"gid://shopify/Customer/12345","email":"[email protected]"}
3
{"id":"gid://shopify/Customer/67890","email":"[email protected]"}
4
{% endcapture %}
5
​
6
{% assign json_objects = jsonl_string | parse_jsonl %}
7
​
8
{{ json_objects | map: "email" | join: ", " }}
Copied!
The parse filters raise errors when invalid JSON or JSONL is received. To ignore parse errors during parse_json, and to return null when an error is encountered, add silent: true to the filter's options:
1
{% assign should_be_nil = "{{" | parse_json: silent: true %}
Copied!

parse_xml *

Use this filter to parse an XML string. (Under the hood, this filter calls Hash::from_xml.) Useful for processing output from third-party APIs, either by responding to "http" actions, or by parsing content from inbound webhooks.
1
{% capture xml_string %}
2
<foo>
3
<bar>baz</bar>
4
<bar>
5
<qux>quux</qux>
6
</bar>
7
</foo>
8
{% endcapture %}
9
​
10
{% assign xml = xml_string | parse_xml %}
11
​
12
{{ xml | json }}
Copied!
1
{"foo":{"bar":["baz",{"qux":"quux"}]}}
Copied!

shopify *

This filter accepts a GraphQL query string, sends it to Shopify, and returns the full response – including "data" and "errors".
Tip: Use Shopify's GraphiQL query builder to quickly and precisely assemble your queries.
1
{% capture query %}
2
query {
3
shop {
4
primaryDomain {
5
host
6
id
7
sslEnabled
8
url
9
}
10
myshopifyDomain
11
}
12
}
13
{% endcapture %}
14
​
15
{{ query | shopify | json }}
Copied!
Response
1
{
2
"data": {
3
"shop": {
4
"primaryDomain": {
5
"host": "graphql-admin.myshopify.com",
6
"id": "gid://shopify/Domain/33896136726",
7
"sslEnabled": true,
8
"url": "https://graphql-admin.myshopify.com"
9
},
10
"myshopifyDomain": "graphql-admin.myshopify.com"
11
}
12
},
13
"extensions": {
14
"cost": {
15
"requestedQueryCost": 2,
16
"actualQueryCost": 2,
17
"throttleStatus": {
18
"maximumAvailable": 1000,
19
"currentlyAvailable": 975,
20
"restoreRate": 50
21
}
22
}
23
}
24
}
Copied!

String filters

Mechanic supports all of the string filters available in Liquid - https://shopify.dev/api/liquid/filters/string-filters.

append

Code
Output
1
{{ 'report' | append: '.pdf' }}
Copied!
1
report.pdf
Copied!

capitalize

Code
Output
1
{{ 'mechanic' | capitalize }}
Copied!
1
Mechanic
Copied!

downcase, upcase

Code
Output
1
{{ 'stop yelling it at me' | upcase }}
2
{{ 'STOP YELLING AT ME' | downcase }}
Copied!
1
STOP YELLING AT ME
2
stop yelling at me
Copied!

e164 *

This filter accepts a phone number – country code is required! – and outputs it in standard E.164 format. If the number does not appear valid, the filter returns nil.
1
{{ "1 (312) 456-7890" | e164 }}
2
=> "13124567890"
3
​
4
{{ "+43 670 1234567890" | e164 }}
5
=> "436701234567890"
6
​
7
{{ "000" | e164 | json }}
8
=> "null"
Copied!

escape, escape_once

match *

Use this filter to match a string with a Ruby-compatible regular expression pattern (see Regexp).
This filter returns the entire matched string (i.e. MatchData#to_s). Use the "captures" or "named_captures" lookups to receive an array or hash of captures, respectively (i.e. MatchData#captures, MatchData#named_captures).
This filter only returns the first match found. To find all available matches in a string, use scan.
1
{{ "It's a lovely day!" | match: "(?<=a ).*(?= day)" }}
2
=> "lovely"
3
​
4
{% assign match = "It's a lovely day!" | match: "a (bucolic|lovely) day" %}
5
{{ match.captures }}
6
=> ["lovely"]
7
​
8
{% assign match = "It's a lovely day!" | match: "a (?<adjective>bucolic|lovely) day" %}
9
{{ match.named_captures }}
10
=> {"adjective" => "lovely"}
11
​
12
{% assign match = "It's a lovely day!" | match: "a (?i:LOVELY) day" %}
13
{{ match }}
14
=> "a lovely day"
Copied!

md5

newline_to_br

prepend

Code
Output
1
{{ 'great to meet you.' | prepend: 'It was ' }}
Copied!
1
It was geat to meet you
Copied!

remove, remove_first

Removes a substring from a string.
Code
Output
1
{{ "Hi everyone! Nice to meet everyone!" | remove: "everyone" }}
2
{{ "Hi everyone! Nice to meet everyone!" | remove_first: "everyone" }}
Copied!
1
Hi ! Nice to meet !
2
Hi ! Nice to meet everyone!
Copied!

replace, replace_first

Replaces a substring with something else.
Code
Output
1
{{ "Matt and Megan love to travel and travel." | replace: 'travel', 'party' }}
2
{{ "Matt and Megan love to travel and travel | replace_first : 'travel', 'party' }}
Copied!
1
Matt and Megan love to party and party.
2
Matt and Megan love to party and travel.
Copied!

scan *

Use this filter to find all available matches in a string, using a Ruby-compatible regular expression pattern (see Regexp).
This filter returns an array of matches, consisting of each matched string (i.e. MatchData#to_s). Use the "captures" or "named_captures" lookups on individual matches to receive an array or hash of captures, respectively (i.e. MatchData#captures, MatchData#named_captures).
This filter returns an array of matches. To only find the first match, use match.
1
{{ "It's a lovely day!" | scan: "[\w']+" }}
2
=> ["It's", "a", "lovely", "day"]
3
​
4
{{ "It's a lovely day!" | scan: "(bucolic|lovely|day)" | map: "captures" }}
5
=> [["lovely"], ["day"]]
6
​
7
{{ "It's a lovely day!" | scan: "(?<punctuation>[[:punct:]])" | map: "named_captures" }}
8
=> [{"punctuation" => "'"}, {"punctuation" => "!"}]
Copied!

sha256, hmac_sha1, hmac_sha256

Generates hexadecimal SHA digests. For binary output instead, add binary: true to the filter's options.
Code
Output
1
{% assign signature = "mechanic" | sha256 %}
2
sha256: {{ signature }}
3
​
4
{% assign signature = "mechanic" | hmac_sha1: "sincerely" %}
5
hmac_sha1: {{ signature }}
6
​
7
{% assign signature = "mechanic" | hmac_sha256: "sincerely" %}
8
hmac_sha256: {{ signature }}
9
​
10
{% comment %}
11
Generating an AWS request signature - adapted from
12
https://docs.aws.amazon.com/general/latest/gr/sigv4-calculate-signature.html
13
{% endcomment %}
14
{% assign kSecret = "wJalrXUtnFEMI/K7MDENG+bPxRfiCYEXAMPLEKEY" %}
15
{% assign prefixed_kSecret = "AWS4" | append: kSecret %}
16
{% assign kDate = "20150830" | hmac_sha256: prefixed_kSecret, binary: true %}
17
{% assign kRegion = "us-east-1" | hmac_sha256: kDate, binary: true %}
18
{% assign kService = "iam" | hmac_sha256: kRegion, binary: true %}
19
{% assign kSigning = "aws4_request" | hmac_sha256: kService %}
20
aws: {{ kSigning }}
Copied!
1
sha256: 6c8a739536961bcf34dccc343908406d48139344da4754d4cfe43dcf8d662607
2
​
3
hmac_sha1: 0425a4dbbe0588be87fb51b5706c2244401bc73a
4
​
5
hmac_sha256: 4b8e2bcf66f95b21f74f491eacc1459b0c9ea6723355174af52ded391f9326ea
6
​
7
aws: c4afb1cc5771d871763a393e44b703571b55cc28424d1a5e86da6ed3c154a4b9
Copied!

size

Returns the integer length of the input string.

slice

This filter also works for arrays! And there's a different behavior available for hashes.
This filter accepts an integer offset, and an optional integer length (defaulting to 1). It returns a substring, beginning at the provided index, having the provided length.
Negative offsets begin counting from the end of the string.
1
{{ "12345" | slice: 3 }}
2
=> "4"
3
​
4
{{ "12345" | slice: 3, 2 }}
5
=> "45"
6
​
7
{{ "12345" | slice: -3, 2 }}
8
=> "34"
Copied!

split

Takes a substring, and uses it to split a string into an array.
Code
Output
1
{% assign quote = "love,is,all,you,need!" | split: ',' %}
2
​
3
{% for word in quote %}
4
{{ quote }}
5
{% endfor %}
Copied!
1
love
2
is
3
all
4
you
5
need!
Copied!

strip, lstrip, rstrip

The strip filter removes whitespace from both sides of a string. The lstrip filter removes whitespace from the left side; the rstrip filter removes whitespace from the right side.
Code
Output
1
{{ ' why do we have so many spaces? ' | strip }}
Copied!
1
why do we have so many spaces?
Copied!

strip_html

strip_newlines

truncate, truncatewords

unindent *

Use this filter on strings to remove indentation from strings.
Code
Output
1
{% capture message %}
2
Hello, friend!
3
It's a mighty fine day!
4
{% endcapture %}
5
​
6
{{ message }}
7
{{ message | unindent }}
Copied!
1
Hello, friend!
2
It's a mighty fine day!
3
​
4
​
5
Hello, friend!
6
It's a mighty fine day!
Copied!

url_decode, url_encode

Number filters

currency *

Formats a number (given as an integer, float, or string) as currency. Called with no arguments, this filter uses the store's primary currency and default locale.
A three-character ISO currency code may be specified as the first argument; currency support is drawn from the money project. The locale may be overridden as a named option; locale support is drawn from rails-i18n.
Code
Output
1
{{ "100000.0" | currency }}
2
{{ 100000.0 | currency: "EUR" }}
3
{{ 100000 | currency: "EUR", locale: "fr" }}
4
{{ 100000 | currency: locale: "fr" }}
Copied!
1
$100,000.00
2
€100,000.00
3
€100 000,00
4
$100 000,00
Copied!
Note that this filter does not automatically append the currency ISO code (e.g. it will not generate output resembling "€100,000.00 EUR"). To add the ISO code manually, use one of these examples:
1
{{ price | currency }} {{ shop.currency }}
2
{{ price | currency | append: " " | append: shop.currency }}
Copied!

Math filters

    abs – Returns the absolute value of the input. No arguments.
    at_most – Accepts one argument; returns either the input or the argument, whichever is lesser.
    at_least – Accepts one argument; returns either the input or the argument, whichever is greater.
    ceil – Rounds a float to the next highest integer.
    divided_by – Accepts one argument; divides the input by the argument. If both the input and arguments are integers, returns an integer; otherwise, returns a float.
    floor – Rounds a float down to the next highest integer.
    minus – Accepts one argument; returns the input minus the argument.
    plus – Accepts one argument; returns the input plus the argument.
    round – Rounds a float to the nearest integer.
    times – Accepts one argument; divides the input by the argument. If both the input and arguments are integers, returns an integer; otherwise, returns a float.
    modulo – Accepts one argument; divides the input by the argument and returns the remainder.

Array filters

concat

Concatenates two arrays into a single array.
Code
Output
1
{% assign lunch = "sandwich, apple, soup" | split: ", " %}
2
{% assign dinner = "pasta, pizza, salad" | split: ", " %}
3
​
4
{% assign meals = lunch | concat: dinner %}
5
​
6
{{ meals | join: ", " }}
7
​
8
{% assign breakfast = "eggs, oatmeal, toast" | split: ", " %}
9
​
10
{% assign meals = breakfast | concat: lunch | concat: dinner %}
11
​
12
{{ meals | join: ", " }}
Copied!
1
sandwich, apple, soup, pasta, pizza, salad
2
eggs, oatmeal, toast, sandwich, apple, soup, pasta, pizza, salad
Copied!

first, last

Returns the first or last element of an array. You can use first or last in dot notation inside of tags.
Code
Output
1
{% comment %}
2
product.tags = "VIP", "New", "Canada"
3
{% endcomment %}
4
​
5
{{ custom.tags | first }}
6
{{ customer.tags | last }}
7
​
8
{% if customer.tags.first == "VIP" %}
9
This customer is a VIP!
10
{% endif %
11
​
12
{% if customer.tags.last == "Canada" %}
13
Eh!
14
{% endif %}
Copied!
1
VIP
2
Canada
3
This customer is a VIP!
4
Eh!
Copied!

in_groups *

This filter is an implementation of Array#in_groups. It accepts an array, and an integer count, and – optionally – a "fill_with" option.
Code
Output
1
{{ "1,2,3" | split: "," | in_groups: 2 | json }}
Copied!
1
[["1","2"],["3",null]]
Copied!
Code
Output
1
{{ "1,2,3" | split: "," | in_groups: 2, fill_with: false | json }}
Copied!
1
[["1","2"],["3"]]
Copied!

in_groups_of *

This filter is an implementation of Array#in_groups_of. It accepts an array, and an integer count, and – optionally – a "fill_with" option.
This filter is particularly useful when performing work in batches, by making it easy to split an array of potentially large size into smaller pieces of controlled size.
Code
Output
1
{{ "1,2,3,4,5" | split: "," | in_groups_of: 2 | json }}
Copied!
1
[["1","2"],["3","4"],["5",null]]
Copied!
Code
Output
1
{{ "1,2,3,4,5" | split: "," | in_groups_of: 2, fill_with: false | json }}
Copied!
1
[["1","2"],["3","4"],["5"]]
Copied!

index_by *

This filter accepts the name of an object property or attribute, and returns a hash that whose values are every element in the array, keyed by every element's corresponding property or attribute.
Code
Output
1
{% capture variants_json %}
2
[
3
{
4
"id": 12345,
5
"sku": "ONE"
6
},
7
{
8
"id": 67890,
9
"sku": "TWO"
10
}
11
]
12
{% endcapture %}
13
​
14
{% assign variants = variants_json | parse_json %}
15
​
16
{{ variants | index_by: "sku" | json }}
Copied!
1
{
2
"ONE": {
3
"id": 12345,
4
"sku": "ONE"
5
},
6
"TWO": {
7
"id": 67890,
8
"sku": "TWO"
9
}
10
}
Copied!

join

Creates a string from the elements of an array using a character passed as an argument.
Code
Output
1
{% comment %}
2
product.tags = "VIP", "New", "Canada"
3
{% endcomment %}
4
​
5
{{ customer.tags | join: ', ' }}
Copied!
1
VIP, New, Canada
Copied!

map

Given an array of objects that contain attributes (e.g. name) and values (e.g. matt), we can use map to get a new array of values for a specific attribute of the objects in the array. In the below example, we have an array of products, and each product has a title. Using map we can create a new array of only product titles.
Code
Output
1
{% comment %}
2
product.titles = "Apple", "Orange", "Pepper", "Cheese"
3
{% endcomment %}
4
​
5
{% assign product_titles = products | map: 'title' %}
6
​
7
{{ product_titles }}
Copied!
1
AppleOrangePepperCheese
Copied!

push *

This filter appends any number of arguments onto the provided array, returning a new array, leaving the original unmodified.
Code
Output
1
{% assign count_to_three = "one,two,three" | split: "," %}
2
​
3
{% assign count_to_five = count_to_three | push: "four", "five" %}
4
​
5
{{ count_to_five | join: newline }}
Copied!
1
one
2
two
3
three
4
four
5
five
Copied!

reverse

This filter returns a new array, containing the contents of the original in reverse order.

sample *

This filter can be used on any array. Used without any arguments, it returns a single random element from the array. Provide an integer argument to return another array of that size, containing a random subset of the input array.
1
{{ "1,2,3" | split: "," | sample }}
2
=> "2"
3
​
4
{{ "1,2,3" | split: "," | sample: 2 | join: "," }}
5
=> "3,1"
Copied!

slice

This filter also works for strings! And there's a different behavior available for hashes.
This filter accepts an integer offset, and an optional integer length (defaulting to 1). If the length is 1, it returns the single element found at that index of the input array. Otherwise, it returns a slice of the array, beginning at the provided index, having the provided length.
Negative offsets begin counting from the end of the array.
1
{{ "1,2,3,4,5" | split: "," | slice: 3 }}
2
=> "4"
3
​
4
{{ "1,2,3,4,5" | split: "," | slice: 3, 2 | join: "," }}
5
=> "4,5"
6
​
7
{{ "1,2,3,4,5" | split: "," | slice: -3, 2 | join: "," }}
8
=> "3,4"
Copied!

size

This filter returns the number of elements in the given array.

sort

Sorts an array by a given attribute.
Code
Output
1
{% assign big_spenders = customers | sort: "total_spent" %}
2
​
3
{% for customer in big_spenders %}
4
<h4>{{ customer.email }}</h4>
5
{% endfor %}
Copied!
Copied!

sum *

Use this on an array of numbers to quickly generate their sum.
1
{{ "[1, 2, 3]" | parse_json | sum }}
2
=> 6
Copied!

uniq

Removes any duplicates in an array, resulting in a new array of distinct values.
Code
Output
1
{% assign cars = "Honda Ford Toyota Jeep VW Honda VW" %}
2
{{ cars | split: ' ' | uniq | join: ' ' }}
Copied!
1
Honda Ford Toyota Jeep VW
Copied!

unshift *

This filter prepends any number of arguments onto the provided array, returning a new array, leaving the original unmodified.
Code
Output
1
{% assign count_two_three = "two,three" | split: