sendgrid / docs

Repository of Twilio SendGrid's product documentation.
https://sendgrid.com/docs
MIT License
236 stars 967 forks source link

Handlebars global variable access is different in UI vs the sent emails #6584

Closed DannyJoris closed 3 years ago

DannyJoris commented 3 years ago

Apologies if this does not belong here. I asked this question to Support, but they referred me to the GitHub org because it was too technical for them.

Using Handlebars, to access global variables inside of conditional or loop blocks you are required to prefix the variable with ../. In SendGrid UI you need to add a ../ for every nested block, or the variable won't be accessed.

When sending a test email though, the variables only get accessed if they are prefixed with a single ../. Multiple ones won't work. I've also been writing the email markup with a local setup of a simple Eleventy.js environment and Handlebars set to "^4.7.7". Here it also works with only a single nested notation.

Expected content

Expected to access global variables using a single ../, no matter how deeply accessed in conditional/loop blocks.

Actual content

Single ../ works on a local environment using Handlebars 4.7.7, and when sending the actual emails, but not in the UI.

Example code

SendGrid UI:

{{#if articles}}
  {{#each articles as |article|}}
    {{#equals @index ../ad.index}}
      {{#equals ../../ad.type 'myAdType'}}
        ...

Actual emails sent by SendGrid & local handlebars 4.7.7:

{{#if articles}}
  {{#each articles as |article|}}
    {{#equals @index ../ad.index}}
      {{#equals ../ad.type 'myAdType'}}
        ...