Sendgrid-nodejs: Variable within subject with dynamic_template_variable_data doesn't work

Created on 2 Dec 2018  路  2Comments  路  Source: sendgrid/sendgrid-nodejs

Issue Summary

I'm trying to insert a dynamical variable into the subject line via this library.
For example: "Hello {{name}}, welcome to {{store_name}}"
My email sends off no problem, but the subject renders {{name}} and {{store_name}} as... just that. No variables are inserted.

Code example:

                 dynamic_template_data: {
                    name: "John",
                    store_name: "My store",
                    subject: "Hello {{name}}, welcome to {{store_name}}!"
                  }

In my template within Sendgrid UI, the subject value is: {{subject}}
I've also tried: {{{subject}}} but no go.

Email is sent and the subject line is...
Hello {{name}}, welcome to {{store_name}}

When it should be...
Hello John, welcome to My store!

unknown or a question

Most helpful comment

Hmm.. Just found that I can't do this even within the normal email text as well.
For example, in the test data field I have:

{
  "name": "john",
  "text": "Hi {{name}}"
}

But {{text}} simply renders Hi {{name}}, not Hi john.

Sort of a bummer - guess I will have to do it all on my side with code. Cheers @aroach for your help anyways

All 2 comments

You may need to generate the dynamic subject in your code. Or, try adding that dynamic subject in the html template鈥檚 subject line as opposed to in the dynamic_template_data key

Hmm.. Just found that I can't do this even within the normal email text as well.
For example, in the test data field I have:

{
  "name": "john",
  "text": "Hi {{name}}"
}

But {{text}} simply renders Hi {{name}}, not Hi john.

Sort of a bummer - guess I will have to do it all on my side with code. Cheers @aroach for your help anyways

Was this page helpful?
0 / 5 - 0 ratings

Related issues

umarhussain15 picture umarhussain15  路  3Comments

Loriot-n picture Loriot-n  路  4Comments

thinkingserious picture thinkingserious  路  4Comments

Chrischuck picture Chrischuck  路  3Comments

prasoonjalan picture prasoonjalan  路  3Comments