From 43c2aab84b8b0c6cf656b956fb4d662e5eee0908 Mon Sep 17 00:00:00 2001 From: Parker Moore Date: Fri, 13 Mar 2015 16:20:39 -0700 Subject: [PATCH] Add docs for `default` --- _filters/default.md | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 _filters/default.md diff --git a/_filters/default.md b/_filters/default.md new file mode 100644 index 0000000..fa24f7a --- /dev/null +++ b/_filters/default.md @@ -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.