Add docs for default

This commit is contained in:
Parker Moore
2015-03-13 16:20:39 -07:00
parent dc7cd7704f
commit 43c2aab84b

22
_filters/default.md Normal file
View File

@@ -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.