Property Filters

Change the output of a property

 
Filters are simple methods that modify the output of numbers, strings, and arrays. They are placed within the output tag {{ }}  and are denoted by a pipe |  character.

Using Filters

Filters are added after the property they are modifying. For example, collection is the object, products is the property, and count is the filter being applied.
This filter will show the number of products in the collection.
{{collection.products | count}}
Some filters require a filter parameter to function. When this is the case, the parameter should be inserted without any formatting. For example, to set the number of decimals on the price of a product, you can use product as an object, price as the attribute, and moneyWithDecimals as the filter, passing the number of decimal places applicable.

Filters with parameters

The following filter will show the price of a product with 2 decimals, for example: $2.00.
{{product.variant.price | moneyWithDecimals:2}}

Multiple filters

You can use multiple filters on a single property. Filters are applied from left to right and each filter should be separated by a pipe character `|` .
{{product.variant.compareAtPrice | minus: product.variant.price | moneyWithDecimals:2}}

All filters

Filters can only be used on the type they are assigned to. For example, a string filter will not work on an array or a number.