【发布时间】:2019-08-09 02:02:46
【问题描述】:
我有一些看起来像这样的测试数据:
{
"firstName":"Ben",
"products": [{
"name": "first product",
"position": 0
}, {
"name": "second product",
"position": 1
}, {
"name": "third product",
"position": 2
}]
}
在我的模板中,我有这样的东西:
<p>Hi {{firstName}}</p>
效果很好。 现在我想循环浏览我的产品
所以我尝试了这个:
{{#each products}}
{{#if this.position == 0}}
<h1>{{this.name}}</h1>
{{else}}
<h2>{{this.name}}</h2>
{{/if}}
{{/each}}
但它不起作用。 我也找不到任何有关执行 if 语句的文档。我找到的最接近的是:
https://sendgrid.com/docs/ui/sending-email/using-handlebars/
它谈到“Basic If, Else, Else If”,这表明有更高级的版本,但我找不到它的文档....
有谁知道我做错了什么?
PS:我的示例仅针对这篇文章进行了简化。
【问题讨论】:
标签: sendgrid sendgrid-templates