gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-03 07:40:14 24 4
gpt4 key购买 nike

我想在 Liquid 中使用带有多个条件的 if 语句。像这样的东西:

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

多个条件似乎不起作用。我的语法是否错误,或者 Liquid 无法处理此类 if 语句?

最佳答案

不幸的是,Liquid 的 bool 代数实现很差。

使用液体的operatorstags ,这是一个肮脏的方法来实现它:

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

关于if-statement - 如何在 Liquid 的 if 语句中使用多个参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23054564/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com