When dealing with Jekyll template and use of Liquid language one may take care when assign Boolean expression to a variable: its does not work!!!! 😭
The assign tag only supports raw Boolean (i.e. true
or false
). Trying to assign a Boolean expression such as:
{% raw %} {% assign vars = 2 == 1 %} {% endraw %}
inexplicably assigns “2” to vars
.
To my knowledge, the only way is to use conditional statement to assign Boolean values 😞 , such as follows:
{% raw %}
{% assign enable_A=false %}
{% assign enable_B=true %}
{% if page.param1==true or page.param2==true %}{%assign enable_A=true%}{% endif %}
{% if page.param2==false or enable_A==true %}{%assign enable_B=false%}{% endif %}
{% endraw %}
Secondly, when mixing the use of Boolean variable with the Liquid default
filter, one may also take care on the ‘basic’ behavior of the filter. Basically in the following snippet code:
{% raw %}{% assign varA = false %}
{% assign vars = varA | default: true %}{% endraw %}
vars
is set to the default true
value as the Liquid default
filter will set the value only if “the left side is nil
, false
, or empty
”.