Handling boolean values

Utility for easy comparison of opt-ins and boolean values in your templates

lazy_boolean filter

This utility can be used to easily compare a user-entered values (strings and numbers) and determine if its True or False. It contains logic for common user and dataset entered values.

Examples

<div class="example">
<p>Yes: {{ 'Yes'|lazy_boolean }}</p>
<p>1: {{ 1|lazy_boolean }}</p>
<p>No: {{ 'No'|lazy_boolean }}</p>
<p>0: {{ 0|lazy_boolean }}</p>
</div>
{% set some_value = 'Yes' %}
{% if some_value|lazy_boolean %}
<h2>Value is Yes - should show</h2>
{% endif %}
{% set some_value = 'No' %}
{% if some_value|lazy_boolean %}
<h2>Value is No - should not show</h2>
{% endif %}

True/False list

Below is a list of values that this supports.

Value examples

lazy_boolean Response

True, "True", "true", 1, "1", "Yes", "yes", " Yes "

True

False, "False", "false", 0, "0", "No", "no", " No ", "", " "

False