Skip to main content

Liquid Filters

Use Liquid filters to modify the feed output of numbers, strings, variables and objects. Apply Liquid filter to Liquid objects by placing a pipe character | after the Liquid object’s name and attribute {{ object.attribute | filter}}, as shown:

<description>
{{ variant.body_html | strip_html | t | truncate: 5000, "" }}
</description>

String Filters

String filters are used to manipulate outputs and variables of the string type.

append

Appends characters to a string.

Example
INPUT
{% assign text = "sales" %}
{{ text | append: '.jpg' }}
OUTPUT
<!-- text = "sales" -->
sales.jpg

capitalize

Capitalizes the first letter of each word in a string.

Example
INPUT
{% assign text = "capitalize me" %}
{{ text | capitalize }}

OUTPUT
<!-- text = "capitalize me" -->
Capitalize Me

downcase

Brings each uppercase character in a string to lowercase.

Example
INPUT
{{ product.title | downcase }}
OUTPUT
<!-- product.title = "RED Jacket" -->
red jacket

escape

Replaces characters in a string with escape sequences so that the string can be used in a URL. Note: a browser will visually display escape symbols as HTML tags.

Example
INPUT
{{ product.title | escape }}
OUTPUT
<!-- product.title = "<p>Red Jacket</p>" -->
&lt;p&gt;Red Jacket&lt;/p&gt;

escape_once

Replaces characters in a string with escape sequences without changing already existing escaped entities in this string.

Example
INPUT
{{ product.title | escape_once }}
OUTPUT
<!-- product.title = "&lt;Red & Jacket&lt;" -->
&lt;Red &amp; Jacket&lt;

newline_to_br

Inserts a <br> linebreak HTML tag in front of each line break in a string.

Example
INPUT
{{ product.title | newline_to_br }}
OUTPUT
<!-- product.title = "Gaming Marker 
Maker
Starter
Kit" -->
Gaming Marker
<br/>
Maker
<br/>
Starter
<br/>
Kit

prepend

Prepends given characters to a string.

Example
INPUT
{{ product.title | prepend: 'Bestseller ' }}
OUTPUT
<!-- product.title = "Gaming Marker" -->
Bestseller Gaming Marker

remove

Removes every occurrence of a given substring.

Example
INPUT
{{ product.title | remove: 'Holiday sale' }}
OUTPUT
<!-- product.title = "Holiday sale Gaming Marker Holiday sale" -->
Gaming Marker

removefirst

Removes the first occurrence of a given substring.

Example
INPUT
{{ product.title | remove: 'Holiday sale' }}
OUTPUT
<!-- product.title = "Holiday sale Gaming Marker Holiday sale" -->
Gaming Marker Holiday sale

replace

Replaces all occurrences of a given substring with another substring.

Example
INPUT
{{ product.title | replace: 'Bestseller', 'Hot sales' }}

OUTPUT
<!-- product.title = "Bestseller Gaming Marker" -->
Hot sales Gaming Marker

replace_first

Replaces the first occurrence of a given substring with another substring.

Example
INPUT
{{product.title | replace_first: 'Bestseller', 'Hot sales' }}
OUTPUT
<!-- product.title = "Bestseller Gaming Marker Bestseller" -->
Hot sales Gaming Marker Bestseller

singular

Converts a word to its singular form

Example
INPUT
{{ product.collection_title | singular }}
OUTPUT
<!-- product.collection_title = Jackets -->
Jacket

split

Splits a string by a given substring.

Example
INPUT
{% assign title = variant.title | split: ' ' %}
{% for word in title %}
{{ word }} -
{% endfor %}
OUTPUT
<!-- variant.title = Superhero toys bestseller -->
Superhero - toys - bestseller -

strip_html

Strips all HTML tags from a string.

Example
INPUT
{{ product.body_html | strip_html }}

OUTPUT
<!-- product.body_html = "<u>Red</u> Jacket" -->
Red Jacket

stripnewlines

Removes any line breaks/newlines from a string.

Example
INPUT
{{ product.body_html | strip_newlines }}
OUTPUT
<!-- product.title = Gaming 
marker -->
Gaming marker

truncate

Truncates a string down to the given number of characters.

Example

The truncated string includes a ... mark, which counts into the specified limit of included symbols.

INPUT
{{ product.description | truncate: 20 }}
OUTPUT
<!-- product.description = "Bestseller product during the holiday season this year" -->
Bestseller produc...

Avoid the occurrence of ... at the end of the truncated string by using | truncate: '20',''

INPUT
{{ product.description | truncate: '20','' }}
OUTPUT
<!-- product.description = "Bestseller product during the holiday season this year" -->
Bestseller product d

truncatewords

Truncates a string down to the given number of words.

Example

If you don't need a ... mark at the end of the truncated string use | truncatewords: '5',''.

INPUT
{{ product.description | truncatewords: 5 }}
OUTPUT
<!-- product.description = "Bestseller product during the holiday season this year" -->
Bestseller product during the holiday...

upcase

Makes all characters of a string uppercase.

Example
INPUT
{{ product.title | upcase }}
OUTPUT
<!-- product.title = "gaming marker" -->
GAMING MARKER

Money filters

Money filters allow change format prices.

currency

Add a letter mark of a currency used in a store.

Example
INPUT
{{ variant.price | currency }}
OUTPUT
1.47 EUR

convert_to_currency

Generates the feed with a currency that is different from the store’s default currency. Omega Shopping Feed utilizes currency exchange rates that Shopify provides. The feed can be converted only to currencies available in this list.

Example
INPUT
{{ variant.price | convert_to_currency: 'USD' }}
OUTPUT
<!-- currency = EUR -->
15.62 USD

money_without_currency

Formats the price with two decimals.

Example

Two decimals in price value are required by marketplaces, for example $1.99. Values like $1.501, which can result from math operations on price, are not allowed.

INPUT
{{ product.price | money_without_currency }}
OUTPUT
<!-- product.price = 21.12345 -->
21.12

Math filters

Math filters allow you to apply mathematical tasks. And, as with any other filters, they are applied in order of left to right.

ceil

Rounds an output up to the nearest integer.

Example
INPUT
{% assign number = 4.3 %}
{{ number | ceil }}
OUTPUT
<!-- number = 4.3 -->
5

divideby

Divides an output by a number. The result is rounded down to the nearest integer.

Example
INPUT
{{ product.price | divided_by: 10 }}
OUTPUT
<!-- product.price = 200 -->
20

floor

Rounds an output down to the nearest integer.

Example
INPUT
{{ product.price | floor }}

OUTPUT
<!-- product.price = 4.6 -->
4

minus

Subtracts a number from an output.

Example
INPUT
{{ product.price | minus: 15 }}
OUTPUT
<!-- product.price = 20 -->
5

modulo

Returns the remainder of a division operation.

Example
INPUT
{{ product.price | modulo: 2 }}
OUTPUT
<!-- product.price = 21 -->
1

round

Rounds the output to the nearest integer. In case you need to get the item price rounded to two decimals, use the money_without_currency filter.

Example
INPUT
{{ product.price | round }}
OUTPUT
<!-- product.price = 2.3657 -->
2

times

Multiplies an output by a number.

Example
INPUT
{{ product.price | times: 2.0 }}
OUTPUT
<!-- product.price = 10 -->
20

Array filters

Array filters change the output of arrays.

first

Returns the first item of an array.

Example
INPUT
{{ variant.tags | first }}
OUTPUT
<!-- variant.tags = [shoes summer women] -->
shoes

index

Returns the specified index location in an array.

Example
INPUT
{{ variant.tags[0] }}
OUTPUT
<!-- variant.tags = [apparel accessories women] -->
apparel

join

Generates a string by joining the elements of an array with the specified character.

Example
INPUT
{{ variant.tags | join: ', ' }}
OUTPUT
<!-- variant.tags = [summer beach accessories] -->
summer, beach, accessories

last

Returns the last element of an array.

Example
INPUT
{{ variant.tags | last }}
OUTPUT
<!-- variant.tags = [summer beach accessories] -->
accessories

map

Accepts an attribute of an array element as a parameter. Then creates an array from each element's value of the given array.

Example
INPUT
<products>
{% for product in context.products %}
{% assign variant_prices = product.variants | map: 'price' %}
<item>
{% for variant_price in variant_prices %}
<price>{{ variant_price }}</price>
{% endfor %}
</item>
{% endfor %}
</products>
OUTPUT
<products>
<item>
<price>26</price>
</item>
<item>
<price>32</price>
</item>
</products>

reverse

Reverses the array elements order.

Example
INPUT
{{ product.tags | reverse }}
OUTPUT
<!-- product.tags = [toys summer beach] -->
[beach summer toys]

The | reverse filter can be used with strings. First use | split: '' filter to split the string, and when the generated array is reversed - apply | join: '' filter to generate a string from the array.

INPUT
{{ product.title | split: '' | reverse | join: '' }}
OUTPUT
<!-- product.title = "Gaming" -->
gnimaG

size

Returns the number of array elements.

Example
INPUT
{{ product.tags | size }}
OUTPUT
<!-- product.tags = [shoes clothes toys] -->
3

Additionally, | size can return the number of characters in a string.

INPUT
{{ product.title | size }}
OUTPUT
<!-- product.title = Gaming marker -->
13

sort

Sorts the elements of an array by a given attribute of an element in the array.

Example
INPUT
{% assign prices = '67, 12, 99, 23, 56' | split: ',' %}
{{ prices | sort }}
OUTPUT
[12 23 56 99 67]

where

Creates an array that includes only the objects with a given property value

Example
INPUT
{% for product in context.products %}
<![CDATA[{{ product.variants | where: "in_stock" | map: 'option1' | remove_empty | uniq | join: ", " }}]]>
{% endfor %}
OUTPUT
black, yellow, blue, white

Alternatively to using where the array of objects with a given property value can be obtained using if operator:

INPUT
{% for product in context.products %}
{% if product.title contains 'TOY' %}
<item>
<name>{{ product.title }}></name>
</item>
{% endif %}
{% endfor %}
OUTPUT
<item>
<name>TOY Mobile Command Center></name>
</item>
<item>
<name>TOY Fun Family></name>
</item>
<item>
<name>TOY Juniors></name>
</item>

Additional filters

General filters serve many different purposes like set format, translations.

date

Displays a timestamp and converts it into another date format. Here are some format directives:

  • %a - the abbreviated day of the week (Mon)
  • %b - the abbreviated month name (Jan)
  • %^b - uppercased (JAN)
  • %d - day of the month, zero-padded (01..31)
  • %-d - no-padded day of the month (1..31)
  • %y - year (00..99)
  • %k - an hour of the day, 24-hour clock, blank-padded ( 0..23)
  • %M - minute of the hour (00..59)

Refer to Ruby documentation for date format directives.

Example
INPUT
{{ product.variant_created_at | date: "%a, %b %d, %y" }}
OUTPUT
<!-- product.variant_created_at = "2022-04-25 16:15:22 +0300 EEST" -->
Mon, Apr 25, 22

default

Sets a default value for a variable with no assigned value.

Example
INPUT
{{ price | default: 1.99 }}
OUTPUT
<!-- price = "" -->
1.99

debug

Use it to inspect a Liquid object.

Example
INPUT
{{ product.title | debug }}
OUTPUT
<!-- product.title = "Toy Mobile Command Center" -->
debug(Toy Mobile Command Center)

t

Translates text to another language. Change the language for translation in the feed settings.

Example
INPUT
{{ product.body_html | t }}
OUTPUT
<!-- product.body_html = "Red Jacket" -->
Chaqueta Roja

img_url

Resize image

Example
INPUT
you can specify exact dimensions:
{{ product.image_url | img_url: "300x300" }}

or you can specify only a width or only a height:
{{ product.image_url | img_url: "600x" }}
{{ product.image_url | img_url: "x300" }}