Announcements
The Google Cloud Community will be in read-only from July 16 - July 22 as we migrate to a new platform; refer to this community post for more details.

Liquid Boolean "not" Operator

Hi. I’m trying to use the Boolean “not” operator in Liquid. It’s not working as expected, and is documented as a supported function in the Liquid Variable Reference. Example:

    {% assign test1 = true not true %}
    {% assign test2 = false not false %}
    {% assign test3 = true not false %}
    {% assign test4 = false not true %}

    {{test1}}
    {{test2}}
    {{test3}}
    {{test4}}

Output:

true
false
true
false

Can anyone explain the proper way to use this operator? I tried with parenthesis, but it only accepts forms like “true not(true)” not “not true” – you seem to always need something on the left and right side of it. Ideas??

0 1 2,951
1 REPLY 1

I think I figured it out from this post. For anybody who comes across this post in a search, I’ll paste the relevant part:

The assign tag only supports raw booleans (ie. true or false ). Trying to assign a boolean expresion such as:

 {% assign vars = 2 == 1 %} 

inexplicably assigns “2” to vars .

To my knowledge, the only way is to use conditional statement to assign boolean values 😞 , such as follows:

{% 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 %}
Top Labels in this Space