Skip to content

Custom Liquid Filters

Liquid supports a range of filters (functions) that allow you to modify data in a variable. The default filters can be seen in the language documentation. Beyond these standard filters Hello Retail provides a few custom filters.

currencySymbol

Transforms a ISO 4217 currency code the corresponding currency symbol.

Input
{{ "EUR" | currencySymbol }}
Output

Only some currency codes are supported. Currently the following transformations are available:

Currency Code Symbol
AUD $
BGN лв
CAD $
CHF CHF
CNY ¥
CZK
DKK kr
EUR
GBP £
HRK kn
HUF Ft
ISK kr
JPY ¥
KRW
LTL Lt
NOK kr
PLN
RON lei
RUB
SEK kr
THB ฿
UAH
USD $
ZAR R

jsonParse

Transform a json string into an object

Input
{% assign json = '{"color": "Red"}' %}
{% assign obj = json | jsonParse %}
{{ obj.color }}
Output
Red

num

Format a number with a number of decimals, a decimal separator, and a thousands separator. The number will be rounded to the number of decimals provided.

The first argument is the number of decimals. It should be a positive number or zero.

The second argument is the decimal separator - it is optional. The default value is . (dot)

The third argument is the thousands separator, it is optional. The default value is , (comma). You can specify "" (empty string) to ommit the thousands separator. But in most cases, you should just use the round-filter.

Input
{{ 99.99 | num: 0 }}
{{ 0.09 | num: 0 }}
{{ 99.99 | num: 1 }}
{{ 0.09 | num: 1 }}
{{ 99.99 | num: 2 }}
{{ 0.09 | num: 2 }}
{{ 1000000.0999 | num: 1, 'd'}}
{{ 1000000.0999 | num: 4, 'd', 't' }}
{{ 1000000.0999 | num: 4, '-', '' }}
Output
100
0
100.0
0.1
99.99
0.09
1,000,000d1
1t000t000d0999
1000000-0999

price

Format a number according to a price format.

The optional first argument is the price format. If no price format is provided it will default to using the price format configured on the website on My Hello Retail.

The price format is a string of at least 3 characters. The first character will be used as the thousands seperator. The second will be used as the decimal seperator. The third will indicate how decimals will be handled. In all cases the price will be formatted with two decimals. The third character can have 3 different values:

If it is '-' and both decimals are 0 then they are replaced with a '-'.

If it is '#' and both decimals are 0 then they, and the decimal seperator will be removed.

If it is '0' the two zeros are kept.

Input
{{ 99.9 | price }}
{{ 1000.00 | price }}
-
{{ 99.9 | price: ".,-" }}
{{ 1000.00 | price: ".,-" }}
-
{{ 99.9 | price: ".,#" }}
{{ 1000.00 | price: ".,#" }}
-
{{ 99.9 | price: ".,0" }}
{{ 1000.00 | price: ".,0" }}
Output
99.90
1,000.00
-
99,90
1.000,-
-
99,90
1.000
-
99,90
1.000,00

priceWithCurrency

Format a number according to the price format configured on the webshop and include a currency symbol.

The first argument is the currency code.

The optional second argument determines the order of the price and the currency symbol. If the argument is not provided it will use a defult ordering based on the provided currency code. The format is a string containing spaces, '$' or '#'. '#' indicates the position of the price, '$' indicates the position of the currency symbol. Spaces will just be spaces.

Input
{{ 99.9 | priceWithCurrency: "DKK" }}
{{ 99.9 | priceWithCurrency: "USD" }}
-
{{ 99.9 | priceWithCurrency: "DKK", "$#" }}
{{ 99.9 | priceWithCurrency: "USD", "# $" }}
Output
99.90 kr.
$99.90
-
kr.99.90
99.90 $

setUrlParam

When applied to a string it will try to parse the string as a URL and add the given parameters as a query string parameter. It returns the modified string.

The first parameter is the query string variable name. The second parameter is the query string parameter value.

Input
{{ "https://shop.example.com/test" | setUrlParam: "lang", "da" }}
{{ "https://shop.example.com/test?id=1" | setUrlParam: "lang", "da" }}
{{ "https://shop.example.com/test?lang=en" | setUrlParam: "lang", "da" }}
Output
https://shop.example.com/test?lang=da
https://shop.example.com/test?id=1&lang=da
https://shop.example.com/test?lang=da

rawHtml

Used to get the raw unescaped value of a safe string

Input
{{ product.title }}
{{ product.title | rawHtml }}
Output
Cloak > Dagger
Cloak > Dagger