Mechanic include all filters available in Liquid's standard library. We also add a few of our own. :)

add_tag
add_tags
remove_tag
remove_tags

Use these filters to manipulate tag strings. All four of these tag filters are case-sensitive.

For background: Instead of working with tags as arrays, the Shopify API works with tags as comma-delimited strings; this makes it complicated to add or remove tags using only standard Liquid. These filters make it very simple.

{{ "a, b" | add_tag: "c" }}
=> a, b, c

{{ "a, b, e" | add_tags: "c", "d" }}
=> a, b, c, d, e

{{ "a, b, e" | add_tags: "c", "d", sort: false }}
=> a, b, e, c, d

{{ "a, b, c" | remove_tag: "b" }}
=> a, b

{{ "a, b, c" | remove_tags: "a", "c" }}
=> b

If supplied an array, these filters will return an array as well:

{{ "a,b,e" | split: "," | add_tags: "c", "d" | join: "-" }}
=> a-b-c-d-e

{{ "a,b,c,d,e" | split: "," | remove_tags: "c", "d" | join: "-" }}
=> a-b-e

base64
decode_base64

Use these filters to convert strings to their base64 representation, and back again.

{{ "hello!" | base64 }}
=> aGVsbG8h

{{ "aGVsbG8h" | decode_base64 }}
=> hello!

{{ "hello!" | base64 | decode_base64 }}
=> hello!

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.

{% capture query %}
query {
  shop {
    primaryDomain {
      host
      id
      sslEnabled
      url
    }
    myshopifyDomain
  }
}
{% endcapture %}

{{ query | shopify | json }}

=> {"data":{"shop":{"primaryDomain":{"host":"example.myshopify.com","id":"gid://shopify/Domain/1234567890","sslEnabled":true,"url":"https://example.myshopify.com"},"myshopifyDomain":"example.myshopify.com"}},"extensions":{"cost":{"requestedQueryCost":2,"actualQueryCost":2,"throttleStatus":{"maximumAvailable":1000.0,"currentlyAvailable":998,"restoreRate":50.0}}}}

parse_json

Use this filter to transform a JSON string into an object that can be inspected and traversed.

{% capture json_string %}
  {
    "hello": "world"
  }
{% endcapture %}

{% assign json_object = json_string | parse_json %}

hello {{ json_object.hello }}
hello world

sum

Use this on an array of numbers to quickly generate their sum.

{{ "[1, 2, 3]" | parse_json | sum }}
=> 6

unindent

Use this filter on strings to remove indentation from strings.

{% capture message %}
  Hello, friend!
  It's a mighty fine day!
{% endcapture %}

{{ message | unindent }}
Hello, friend!
It's a mighty fine day!
Did this answer your question?