I have some test data that looks like this:
{
"firstName":"Ben",
"products": [{
"name": "first product",
"position": 0
}, {
"name": "second product",
"position": 1
}, {
"name": "third product",
"position": 2
}]
}
In my template, I have something like this:
<p>Hi {{firstName}}</p>
Which works fine. Now I want to loop through my products
So I tried this:
{{#each products}}
{{#if this.position == 0}}
<h1>{{this.name}}</h1>
{{else}}
<h2>{{this.name}}</h2>
{{/if}}
{{/each}}
But it doesn't work. I also can't find any documentation about doing if statements like that. The closest I found was:
https://sendgrid.com/docs/ui/sending-email/using-handlebars/
And it talks about "Basic If, Else, Else If" which suggests there is a more advanced version, but I can't find the documentation for it....
Does anyone know what I am doing wrong?
PS: my examples are simplified just for this post.
It looks like the SendGrid documentation is just using Basic If...
to differentiate from the next section of If with a Root. They used similar titles in sections higher up the page.
Based on that, it doesn't appear that they have logic for "if value equals", just "if field exists", so you'd need to update your JSON to use that format, such as they have in later examples.