如何在带有Liquid的if语句中使用多个参数 [英] How to use multiple arguments in an if statement with Liquid
本文介绍了如何在带有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的实现很差boolean algebra。
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 %}
这篇关于如何在带有Liquid的if语句中使用多个参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文