How to use multiple arguments in an if statement with Liquid

不打扰是莪最后的温柔 提交于 2019-11-28 20:06:47

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 %}
Daniel

Another way you can condense this is to combine else if statements, and booleans don't necessarily need the "==" when evaluating true:

{% if include.featured and product.featured %}
      {% assign test = true %}
{% elsif include.featured == false and product.featured == false %}
      {% assign test = false %}
{% endif %}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!