Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handlebars conditional logic not consistent between SendGrid Preview app and live emails #105

Open
radiovisual opened this issue Oct 25, 2023 · 1 comment

Comments

@radiovisual
Copy link

radiovisual commented Oct 25, 2023

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"

Screenshot 2023-10-25 at 2 54 07 PM

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:

Screenshot 2023-10-25 at 2 39 44 PM

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

desc-different

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

@radiovisual
Copy link
Author

I should point out that even though the documentation on equals says this:
image

my example does not show any coercion happening, I am comparing strings to strings, so I would expect that this statement from the docs does not apply in my usage example. Or am I wrong?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant