If statement 如何在带有Liquid的if语句中使用多个参数

If statement 如何在带有Liquid的if语句中使用多个参数,if-statement,jekyll,liquid,If Statement,Jekyll,Liquid,我想在Liquid中使用带有多个条件的if语句。比如: {% if (include.featured == "true" and product.featured == "true") or (include.featured == "false" and product.featured == "false") %} 多个条件句似乎不起作用。我的语法有错误吗?或者Liquid不能处理这种if语句吗?不幸的是,Liquid的布尔代数实现很差 使用液体和,这里有一个肮脏的方法来实现它: {%

我想在Liquid中使用带有多个条件的
if
语句。比如:

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

多个条件句似乎不起作用。我的语法有错误吗?或者Liquid不能处理这种if语句吗?

不幸的是,Liquid的布尔代数实现很差

使用液体和,这里有一个肮脏的方法来实现它:

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

另一种压缩方法是组合else if语句,布尔值在计算true时不一定需要“==”:

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

您还可以使用if/elsif将所有内容保持在一起。| |“been”或“too:~)在您的特定示例中,您可以使用
{%if include.featured==product.featured%}
elseif拼写为elsif代表jekyll,否则这对我很有帮助。