email-templates
email-templates copied to clipboard
Handlebars conditional logic not consistent between SendGrid Preview app and live emails
Actual Behaviour
The Handlebars conditional statements are not behaving the same way in the SendGrid Email Template Preview application (via https://mc.sendgrid.com/dynamic-templates/{id}
) and the email that is delivered to the email inbox.
Expected Behaviour
The Handlebars logic should behave the same in the Email Preview app and in the Email that is generated by the SendGrid API
Steps to reproduce it
Create a minimal email template example with the following HTML + Handlebars markup:
<!doctype html>
<html>
<head></head>
<body>
Description: {{description}}<br/>
Old Description: {{description_old}}
<hr />
{{#if (notEquals description description_old)}}
<p>"Descriptions are not equal"</p>
{{#if (notEquals description "")}}
<p>"Description changed"</p>
{{else}}
<p>"Description removed"</p>
{{/if}}
{{else}}
<p>"Description not changed"</p>
{{/if}}
</body>
</html>
and use the following JSON data to power the template:
{
"description_old": "This is my old description.",
"description": ""
}
LogCat for the issue There are no errors reported anywhere. Only inconsistent Handlebars behaviors.
Screenshots of the issue
Example 1: Empty Description
{
"description_old": "This is my old description.",
"description": ""
}
I would expect the template to render that the descriptions are not equal and that the descriptions have changed, and this is what appears in the SendGrid Preview App, but in the actual email that is sent to the inbox, it says "Description changed"
not the expected"Description removed"
Example 2: No change in description
{
"description_old": "This is my old description.",
"description": "This is my old description."
}
I would expect to see "Description not changed" in both places, but, the actual email thinks the descriptions are different, showing something different than the preview app:
Example 3: Changed description
{
"description_old": "This is my old description.",
"description": "This is a new description."
}
Here I expect to see "Description changed" in both places, and this time it works as expected in both places
Would you like to work on the issue?
I can of course try to help, but I honestly think this has nothing to do with the email-templates directly. My theory is that the problem is that the Handlebars logic is not the same in the preview app than it is on the SendGrid API.
Note that I was asked to open this issue on Github via SendGrid support ticket number 13993343