mirror of
https://github.com/Shopify/liquid.git
synced 2026-09-19 10:52:48 -07:00
Add docs for default
This commit is contained in:
@@ -0,0 +1,22 @@
|
|||||||
|
---
|
||||||
|
title: default
|
||||||
|
---
|
||||||
|
|
||||||
|
`default` offers a means of having a fall-back value in case your value doesn't exist.
|
||||||
|
|
||||||
|
{% highlight liquid %}
|
||||||
|
{% raw %}
|
||||||
|
{{ product_price | default:2.99 }}
|
||||||
|
// => outputs "2.99"
|
||||||
|
|
||||||
|
{% assign product_price = 4.99 %}
|
||||||
|
{{ product_price | default:2.99 }}
|
||||||
|
// => outputs "4.99"
|
||||||
|
|
||||||
|
{% assign product_price = "" %}
|
||||||
|
{{ product_price | default:2.99 }}
|
||||||
|
// => outputs "2.99"
|
||||||
|
{% endraw %}
|
||||||
|
{% endhighlight %}
|
||||||
|
|
||||||
|
`default` will use its substitute if the left side is `nil`, `false`, or empty.
|
||||||
Reference in New Issue
Block a user