Handlebars Syntax Errors in Twilio SendGrid Templates

When naming handlebars in dynamic templates it is common to encounter certain errors that could be difficult to identify. A common error message is "Your template has been successfully saved, but we've detected an issue with your handlebars code that requires attention".  This guide helps to explain how to identify why the error is occurring and how to resolve it.

Common Reasons for the Error

A handlebars error previously mentioned may result from handlebars in your template not following proper naming conventions. We recommend using the following naming conventions when naming handlebars:

Field names should only use alphanumeric characters (A-Z and 0-9) and underscores (_). Custom fields should only begin with letters A-Z or underscores (_).

Here are some examples of correct and incorrect naming conventions with handlebars syntax:

Correct use:


Incorrect use:

{{{First Name}}}  // Spaces aren't allowed.
{{{1Name}}} // Names should always start with a letter or an underscore.
{{{First&Name}}} // Special characters aren't allowed.

Notice: If attempting to use {{{First Name}}}, the system will let you save the template and will not point out an error. However when dynamic content is passed, the system will not be able to identify a word with spaces. Therefore, the system is not going to be able to replace the information. 
Spaces are meant to be used with a different purpose than naming custom fields or handlebars. For instance, spaces are used with conditionals or iterations

Another common reason for the system to say it "detected an error" is if the handle bars syntax is unbalanced.  For instance, here is an example that would cause an error:

{{unbalanced}}} // unbalanced handlebars with 2 and 3 braces, respectively

Dynamic Templates

If you attempt to save your template with an incorrectly formatted name, you'll likely see a generic error. Here's an example:

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

In this situation, we recommend that you scan the names of your handlebars in the template to try and identify errors. The following image shows the error that you will obtain when attempting to save handlebars with bad naming practices, using special characters, or if the first character of the handlebar is a number:


Once you have updated names appropriately, try to save your template again and check for errors.

Marketing Campaigns

If using Marketing Campaigns ("Marketing > Single Sends"), handlebars syntax is called "custom fields". If errors are present in the names, the Custom Fields system will give you a warning message. You won't be able to create the field until you give it an appropriate name.

For example, I used the special character * here. The system will not let you create the field until you have given an appropriate name. 


Following the above may help avoid errors but if issues persist, please create a ticket via support.sendgrid.com to receive help from our technical support team.

Have more questions? Submit a request