How to return a currency object in liquid

Highlighted
Excursionist
31 3 4

I can see in the Liquid reference that there is a "Currency" object with a "Symbol" attribute

 

The example shows that this code:

Symbol: {{ currency.symbol }}

should produce this output:

Symbol: $ 

 

How can I retrieve the symbol property of "shop.currency" ?

 

I tried shop.currency.symbol with no luck.

How can I use the symbol attribute on the shop currency if it return the ISO value as a string?

0 Likes
Highlighted
New Member
2 0 0

Hi @Giulio1 

It's pretty disappointing that the currency object is inaccessible even though it is stated in the docs. 

I was able to get this to work by accessing shop.money_format and then i used substring to extract the currency symbol from the result. 

It's a bit of an hack but i guess it works (: 

Here is my code: 

 

let shop_symbol = "{{ shop.money_format }}";
  shop_symbol = shop_symbol.trim();
  if (shop_symbol.substring(shop_symbol.length - 1) !== '}' && shop_symbol.substring(shop_symbol.length - 1).length > 0) {
  	shop_symbol = shop_symbol.substring(shop_symbol.length - 1);
  } else {
    shop_symbol = shop_symbol.substring(0, 1);
  }

 

Alternatively, which is way better, you can create a function that just replaces the variables, with your product price. You can find all the possible currency variables in here: https://help.shopify.com/en/manual/payments/currency-formatting

 

 

0 Likes