5

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?

Fjott
  • 1,107
  • 3
  • 15
  • 38

3 Answers3

6

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!
Fjott
  • 1,107
  • 3
  • 15
  • 38
2

I got the same error-message. After pasting the code into a note file and pasting it back in, the formatting was lost. But with the exact same input the error message disappeared.

Unclear to me, why that worked. But maybe it works for others as well.

Leopold
  • 21
  • 1
0

Just came across this same error and I wanted to leave my findings here as I did not see anyone showing the error that I had.

In my case I duplicated the template from another one that was already working fine as I needed one similar to that one. This template was using the "Text" build module as I found it translated quite well to HTML code automatically.

The template used some variables like:

Passenger: {{passangerFullName}}
Dates: {{checkInDate}} - {{checkOutDate}}

But the email was not being send when it was triggered. After trying for I while I checked how the email got translated to HTML and I found something like this:

<div><span>{{passangerFullName}}{{</span><span>&nbsp;</span></div>
<div><br></div>
<div><span>checkInDate}} - {{checkOutDate}}</span><span>&nbsp;</span></div>

So the translation to HTML did not go as expected, first it added some unexpected span tags and then the curly braces from the checkInDate got moved to the previous div (note the braces in bold). That was what caused the error for me.

Moving those braces to the right place (just before checkInDate) solved the error.