default

default

Allows you to specify a fallback in case a value doesn’t exist. default will show its value if the left side is nil, false, or empty.

In this example, product_price is not defined, so the default value is used.

Input

{{ product_price | default: 2.99 }}

Output

2.99

In this example, product_price is defined, so the default value is not used.

Input

{% assign product_price = 4.99 %}
{{ product_price | default: 2.99 }}

Output

4.99

In this example, product_price is empty, so the default value is used.

Input

{% assign product_price = "" %}
{{ product_price | default: 2.99 }}

Output

2.99

© 2005, 2006 Tobias Luetke
Licensed under the MIT License.
https://shopify.github.io/liquid/filters/default/

在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号

意见反馈
返回顶部