如何在带有 Liquid 的 if 语句中使用多个参数 [英] How to use multiple arguments in an if statement with Liquid

查看:24
本文介绍了如何在带有 Liquid 的 if 语句中使用多个参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在 Liquid 中使用带有多个条件的 if 语句.类似的东西:

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") %}

多个条件似乎不起作用.是我语法错误还是 Liquid 无法处理这种 if 语句?

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

推荐答案

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

Unfortunately, Liquid has a poor implementation of boolean algebra.

使用 Liquid 的 operators标签,这是实现它的肮脏方式:

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

这篇关于如何在带有 Liquid 的 if 语句中使用多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆