Search code examples
sendgridsendgrid-templates

Sendgrid - handlebar error msg in dynamic template


I have tried to setup a Sendgrid dynamic template that contains several handlebars, including an Iterator with each The whole email template html can be found her

The test data looks like this:

{
   "total":"1000",
   "items":[
      {
         "text":"Ebook 1",
         "qty":"1",
         "price":"3"
      },
      {
         "text":"Ebook 2",
         "qty":"2",
         "price":"3"
      },
      {
         "text":"ebook 3",
         "qty":"4",
         "price":"3"
      }
   ],
   "name":"John Doe",
   "address01":"Stargate 292",
   "city":"NY",
   "state":"NY",
   "zip":"4567",
   "orderId":"456",
   "expiry":"Nov 9 2021",
   "customerRef":"123"
}

For some reason I keep getting this error when saving:

Your template has been successfully saved, but we've detected an issue with your handlebars code that requires attention.

I cannot find any other error msg that can tell me exactly why and where in the code this error occur.

I am using an {{#each}} iteration, not 100% sure if this is correctly setup

{{#each items}}    
<table>
  <tr>
    <td>{{this.text}}</td>
  </tr>
  <tr>
    <td>{{this.qty}}</td>
  </tr>
  <tr>
    <td>{{this.price}}</td>
  </tr>
</table>
{{/each}}

The other handlebars are just basic ones like {{ name }}, {{ city }} etc.

Do anyone have experience with this kind of error and know how to fix it?


Solution

  • Found the error in this typo:

    {{ customerRef} })
    

    had to change it to

    {{ customerRef }}
    

    Lesson:

    1. Be aware of the curly brackets when using handlebars
    2. Sendgrid error handling will hopefully be more detailed in the future!