{{true and false}} liquid markup returns true in LookML

Hello All,

I was having some unusual behavior with chaining multiple "and"s in a liquid if statements and after troubleshooting, found the following:

{{true and false}} returns true

{{false and true}} returns false

Can anyone shed some light on why liquid responds this way? I found the following:

Shopify/liquid

Liquid markup language. Safe, customer facing template language for flexible web apps. - Shopify/liquid


My next step would be to install my own liquid engine to test whether this issue is limited to Looker, but thought I’d see what the community had to say first. Appreciate any assistance here.

0 4 810
4 REPLIES 4

Can you give a complete example? Here’s my similar test that works:

dimension:test_liquid {    
    sql: 
    {% if true and false %}
    'true'
    {% else %}
    'false'
    {% endif %};;
  }

Hello Quinn,

Thanks for looking into this. Here is my test:

LookML:

sql_always_where:
{{true and false}}

{{false and true}}

;;

SQL result from Explore:

SELECT
batch.“name” AS “batch.name”,
FROM lumen.batch AS batch

WHERE true

false

GROUP BY 1,2
ORDER BY 1
LIMIT 500

The above obviously isn’t valid SQL, but the sql_where tag is a convenient place to test liquid.

Hello Jacob. I’m looking at the shopify documentation here(https://shopify.github.io/liquid/basics/introduction/), and it appears to suggest that logical operations like and are expected to be used within {% %} as opposed to {{ }}.

Objects

Objects tell Liquid where to show content on a page. Objects and variable names are denoted by double curly braces: {{ and }} .

Tags create the logic and control flow for templates. They are denoted by curly braces and percent signs: {% and %} .

Within {{}}, it seems that liquid picks up the first recognizable object. The test {{true and false}} resolves to true, as does {{true andWrongOnPurposeButThisJustGetsIgnored}}.

To Quinn’s point, perhaps what you want is something like:
{% if some_first_criteria and some_second_criteria %}
{% assign all_criteria_met = true %}
{% else %}
{% assign all_criteria_met = false %}
{% endif %}
{{all_criteria_met}}

Ahhh- I had been treating {{}} and {%%} interchangebly as script tags of sorts. That makes perfect sense with that explanation. Thank you for looking into this.

Top Labels in this Space
Top Solution Authors