Allow false

This is useful where we have assignments with default values, where we do not always want the default property to come into action.

There are often configurations within templates where we have an assignment which is specific at firm level. If we want the configurable variable to be equal to false - this will mean that by default, we don’t want something to happen in the template.

No filter

The case below displays the issues faced where previously assigned variables will always display as the default value.

{% assign display_option_gross_profit_percentage = false %}
{{ display_option_gross_profit_percentage }}
{% assign display_option_gross_profit_percentage = display_option_gross_profit_percentage | default:true %}
{{ display_option_gross_profit_percentage }}
Output
false
true

Enabling the filter

We will now see how the allow_false filter can overcome the issue above.

Whenever we assign a variable to a falsy value, i.e. false, nil or empty, the default property comes into play. To avoid that, the filter allow_false can be used.

To enable this filter, we use: allow_false:true

Remember to add a comma (,) in between the default and allow_false filter, else this will stop your syntax working the way it should.

{% assign display_option_gross_profit_percentage = false %}
{{ display_option_gross_profit_percentage }}
{% assign display_option_gross_profit_percentage = display_option_gross_profit_percentage | default:true, allow_false:true %}
{{ display_option_gross_profit_percentage }}
Output
false
false