CASE: allow false in default statement

We’ve seen how we can create a default statement, where we take the default value whenever our statement proves to be nil, false or empty:

So if you have this for example:

{% comment %}create var with output FALSE{% endcomment %}
{% assign my_check = false %}

{% comment %}create var with either a database variable OR the default TRUE{% endcomment %}
{% assign question_a = my_check | default:true %}

{% comment %}display output var{% endcomment %}
{{ question_a }}  

then you’ll see the output of the variable question_a will be true. And that’s because the default attribute skips the value of the var my_check (as that is false) and goes to the default value instead.

If you ever face this situation, in which you want the value ‘false’ be taken into the variable you create with the default attribute, you can by adding allow_false:true like this:

{% assign question_a = my_check | default:true, allow_false:true %}

which will now result in the output of false instead of true.

Perhaps not many use-cases in here, but it avoids reversing your code if you ever face this situation.