I'm currently trying to set up a dynamic template on sendgrid to inform participants, that signed up for an event, about their group allocation. For this I'm providing the following JSON
{
"name": "TestEvent",
"date": "2023-03-06",
"flights":
{
"1": {
"teeTime": "18:00",
"participantIds": [
"123456",
"98765"
]
}
},
"participants": {
"123456": {
"firstName": "Test",
"lastName": "User",
"flight": "1"
},
"98765": {
"firstName": "Example",
"lastName": "Participant",
"flight": "1"
}
}
}
What I'm trying to get from this is basically an Email along the line of this:
18:00 - Flight 1
Test User
Example Participant
(to be continued in case more Groups are provided in JSON, e.g.)
18:10 - Flight 2
User 3
User 4
For this i set up the following structure in the dynamic template
{{#each flights as | flight |}}
{{flight.teeTime}} - Flight {{@key}}
{{#each flight.participantIds as | participant |}}
<br>
{{#with (lookup @root.participants participant) as |participantDetails|}}
{{firstName}} {{lastName}}
{{/with}}
{{/each}}
{{/each}}
When looking at the preview in the sendgrid code editor, all looks well: Sendgrid Preview
However when I send a Test-mail, I only get the "header" row. firstName and lastName are not getting resolved.
18:00 - Flight 1
I'm suspecting a problem within the #with
block and already tried the following options. Actually all of them produce the correct results in the preview
{{#with (lookup @root.participants participant) as |participantDetails|}}
{{#with (lookup ../../participants participant) as |participantDetails|}}
{{#with (lookup @root.participants participant)}}
{{#with (lookup @root.participants [participant]) as |participantDetails|}}
Any Ideas why this is not working? Is there a limitation in nesting loops and with statements?