How to use multiple arguments in an if statement with Liquid

Fisu picture Fisu · Apr 14, 2014 · Viewed 22.9k times · Source

I want to use an if statement in Liquid with multiple conditionals. Something like:

{% if (include.featured == "true" and product.featured == "true") or (include.featured == "false" and product.featured == "false") %}

Multiple conditionals don't seem to work. Have I got the syntax wrong or can Liquid not handle this sort of if statement?

Answer

Sylvain picture Sylvain · Apr 15, 2014

Unfortunately, Liquid has a poor implementation of boolean algebra.

Using Liquid's operators and tags, here is a dirty way to achieve it:

{% if include.featured == true and product.featured == true %}
      {% assign test = true %}
{% endif %}

{% if include.featured == false and product.featured == false %}
      {% assign test = true %}
{% endif %}

{% if test %}
      Yepeeee!
{% endif %}