conditional-statements - bigcommerce 模板中的 {{#if}} 语句中有多个条件

标签 conditional-statements bigcommerce

我想在模板主题(bigcommerce)中使用 2 个条件。我怎样才能这样做?

{{#if schema && product.brand.name '!=' ''}}

我也用过

{{#all schema product.brand.name '!=' ''}}

但没有得到想要的结果。

此外,我们如何检查某些变量或属性是否为空,因为以下语句对我不起作用:

{{#if product.brand.name '==' ''}}

问候,

最佳答案

您应该能够使用 {{#and}} 帮助器来精确比较两个条件。

{{#and schema product.brand.name}} There's both a schema and brand name! {{/and}}

这将检查“schema”和“product.brand.name”的计算结果是否为真实值(意味着它们已被定义并且没有明确为 False 或 0 等)

检查变量是否为空类似于 if 语句检查变量是否被定义:

{{#if customer}} There's a customer! {{/if}}

Cornerstone 存储库中有很多使用这些帮助器的好示例,在该存储库中搜索一些示例以了解情况可能会有所帮助。

以下是“and”帮助器的示例:https://github.com/bigcommerce/cornerstone/blob/3350ea5c2a8cbb53819145bdcdda41dc6fef4f0c/templates/components/products/price-range.html#L1

希望这有帮助!

关于conditional-statements - bigcommerce 模板中的 {{#if}} 语句中有多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49879379/

相关文章:

Excel,查看表中的值,其中行和列都是范围

php - MySQL 使用 And 条件连接

node.js - BigCommerce 和 NodeJS 应用程序 - 身份验证、加载、卸载过程

Javascript 在执行其内容后有条件地执行

c - 如何根据条件语句和 C 输出来修复程序的运行?

php - Bigcommerce产品API

api - BigCommerce 添加产品到购物车 API

BigCommerce webhook 没有触发

python - 评估复杂的条件Python

shipping - Bigcommerce 定制运输处理