if
如果一个特定的条件是真,则渲染一个表达式。
{{#if condition }}
content
{{/if}}
condition
可评估的表达式
表达式
满足条件时要呈现的表达式。
{{#if product.price '>' product.compare_at_price }}
I am a regular product.
{{/if}}
else if
您可以使用else if标记来检查多个条件。
{{#if condition }}
content
{{else}}
content
{{/if}}
{{#if product.type == 'Red' }}
This is a red option!
{{else if product.type == 'Yellow' }}
This is a yellow option!
{{/if}}
else
允许您指定在不满足其他条件时执行的默认表达式。
{{#if product.available }}
This product is available!
{{else}}
This product is sold out!
{{/if}}
if 语句使用子表达式
handlebars 原生支持子表达式,当您想配合其他 helper ,编写复杂的判断语句时,可以使用子表达式调用其他 helper。
{{#if (lowercase product.type) == 'red' }}
This is a red option!
{{/if}}
if 语句使用 and,or
允许您将多个条件按照逻辑 【and 并且】,【or 或者】进行运算。
{{#if product.type == 'yellow' or product.price >= 10 and product.available }}
This is a available yellow type product, or greater than 100 product!
{{/if}}
这篇文章对你有帮助吗?
SHOPLINE