Shopify Liquid 模板 - 或者操作员不工作

Shopify Liquid Template - OR operator not working

我正在努力实现一些非常简单的事情。

我的代码如下:

{% if template != 'index' or template != 'page.jump' %}

如果模板不等于那两个页面,我想做点什么。

但是,在 or

之后似乎没有任何解释

这些都单独工作,我不得不求助于嵌套 if 语句,这很讨厌。

template 不能在液体模板中使用 or 运算符有什么原因吗?

尝试 "and" 运算符。

{% if template != "index" and template != "page.jump" %}

这里似乎还有另一种方法: How to use multiple arguments in an if statement with Liquid

对于液体,它在 2 种条件下完美工作:

  1. 不要使用双引号,只使用单引号
  2. 不要以“不等于”开头你的陈述!= 您可以使用 != 作为语句的第二部分

示例:

{% if product.type == 'Bundle' and product.type != 'Dress'%}