Bigcommerce Stencil Handlebars 助手 'inArray'
Bigcommerce Stencil Handlebars helper 'inArray'
我正在尝试使用 Bigcommerce Handlebars 助手 'inArray'。我将助手解释为能够在数组中找到特定值。我可以让我的 else 语句工作,但它不应该输出任何东西,因为我正在寻找的值确实存在。
来自文档:
{{inArray}}
Block helper that renders the block if an array has the given value. Optionally, you can specify an inverse block to render when the array does not have the given value.
Parameters:
- array {Array}
- value {any}
- options {Object}
- returns {String}
我的样本json:
"custom_fields": [
{
"id": "41005235",
"name": "room",
"value": "Kitchen"
},
{
"id": "41005236",
"name": "REQUIRED (NOT INCLUDED)",
"value": "1 LED 13 WATT BULBS"
},
{
"id": "41005237",
"name": "FINISH",
"value": "BRONZE W/POLISHED BRASS ACCENTS"
}]
我的车把:
{{#inArray custom_fields "FINISH"}}
<h1>it's there</h1>
{{else}}
<h1>it's not there</h1>
{{/inArray}}
您可以尝试使用 {{#each}} 然后使用 if/else 语句来检查值。例如:
{{#each product.custom_fields}}
{{#if name '===' 'FINISH'}}
<h1>It's there</h1>
{{else}}
<h1>It's not there</h1>
{{/if}}
{{/each}}
我正在尝试使用 Bigcommerce Handlebars 助手 'inArray'。我将助手解释为能够在数组中找到特定值。我可以让我的 else 语句工作,但它不应该输出任何东西,因为我正在寻找的值确实存在。
来自文档:
{{inArray}} Block helper that renders the block if an array has the given value. Optionally, you can specify an inverse block to render when the array does not have the given value.
Parameters:
- array {Array}
- value {any}
- options {Object}
- returns {String}
我的样本json:
"custom_fields": [
{
"id": "41005235",
"name": "room",
"value": "Kitchen"
},
{
"id": "41005236",
"name": "REQUIRED (NOT INCLUDED)",
"value": "1 LED 13 WATT BULBS"
},
{
"id": "41005237",
"name": "FINISH",
"value": "BRONZE W/POLISHED BRASS ACCENTS"
}]
我的车把:
{{#inArray custom_fields "FINISH"}}
<h1>it's there</h1>
{{else}}
<h1>it's not there</h1>
{{/inArray}}
您可以尝试使用 {{#each}} 然后使用 if/else 语句来检查值。例如:
{{#each product.custom_fields}}
{{#if name '===' 'FINISH'}}
<h1>It's there</h1>
{{else}}
<h1>It's not there</h1>
{{/if}}
{{/each}}