我想在模板主题(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 存储库中有很多使用这些帮助器的好示例,在该存储库中搜索一些示例以了解情况可能会有所帮助。
希望这有帮助!
关于conditional-statements - bigcommerce 模板中的 {{#if}} 语句中有多个条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49879379/