目前我可以自定義字段全部或全部無。像這樣調用特定的custom_field BigCommerce模板
{{#each product.custom_fields}} {{ id }} : {{ name }} : {{ value }} {{/each}}
但是如果我想通過ID或名稱,如下面的調用只是其中的一個東西。有沒有辦法用模板或其他方式做到這一點?
{{product.custom_fields.id:4.name}}
目前我可以自定義字段全部或全部無。像這樣調用特定的custom_field BigCommerce模板
{{#each product.custom_fields}} {{ id }} : {{ name }} : {{ value }} {{/each}}
但是如果我想通過ID或名稱,如下面的調用只是其中的一個東西。有沒有辦法用模板或其他方式做到這一點?
{{product.custom_fields.id:4.name}}
您可以使用現有的{{如果}}幫手來完成這個
{{#if display_name '===' 'material'}}
{{#each product.custom_fields}}
{{id}} : {{name}} : {{value}}
{{/each}
{{/if}}
您可以通過ID選擇列表項。但是,如果您想按名稱選擇,則需要實現一個條件,如@alyss建議的那樣。
參見:How do I access an access array item by index in handlebars?