diff --git a/use-cases/README.md b/use-cases/README.md index 14552536c..f11dbe798 100644 --- a/use-cases/README.md +++ b/use-cases/README.md @@ -9,6 +9,7 @@ This documentation provides examples for specific SendGrid v3 API use cases. Ple * [Handling Success/Failure/Errors](https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/success-failure-errors.md) * [Advanced Usage](https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/advanced.md) * [Transactional Templates](https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-templates.md) + * [Legacy Transactional Templates](https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/transactional-legacy-templates.md) * [Attachments](https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/attachments.md) * [Customization Per Recipient](https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/customization.md) * [Manually Providing Content](https://github.com/sendgrid/sendgrid-nodejs/blob/master/use-cases/manual-content.md) diff --git a/use-cases/transactional-legacy-templates.md b/use-cases/transactional-legacy-templates.md new file mode 100644 index 000000000..40a1dda50 --- /dev/null +++ b/use-cases/transactional-legacy-templates.md @@ -0,0 +1,64 @@ +# (LEGACY) Transactional Templates + +For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing. + +Template ID (replace with your own): + +```text +13b8f94f-bcae-4ec6-b752-70d6cb59f932 +``` + +Email Subject: + +```text +<%subject%> +``` + +Template Body: + +```html + + + + + +Hello {{name}}, +

+I'm glad you are trying out the template feature! +

+<%body%> +

+I hope you are having a great day in {{city}} :) +

+ + +``` + +```js +const sgMail = require('@sendgrid/mail'); +sgMail.setApiKey(process.env.SENDGRID_API_KEY); +sgMail.setSubstitutionWrappers('{{', '}}'); // Configure the substitution tag wrappers globally +const msg = { + to: 'recipient@example.org', + from: 'sender@example.org', + subject: 'Hello world', + text: 'Hello plain world!', + html: '

Hello HTML world!

', + templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932', + substitutions: { + name: 'Some One', + city: 'Denver', + }, +}; +sgMail.send(msg); +``` + +Alternatively, you may specify the substitution wrappers via the msg object as well. This will override any wrappers you may have configured globally. + +```js +const msg = { + ... + substitutionWrappers: ['{{', '}}'], + ... +}; +``` diff --git a/use-cases/transactional-templates.md b/use-cases/transactional-templates.md index aae92a8d0..0e8c40077 100644 --- a/use-cases/transactional-templates.md +++ b/use-cases/transactional-templates.md @@ -1,19 +1,11 @@ -# (LEGACY) Transactional Templates - -IF YOU ARE USING OUR NEW TEMPLATES, PLEASE SEE [THIS ISSUE](https://github.com/sendgrid/sendgrid-nodejs/issues/703). +# Transactional Templates For this example, we assume you have created a [transactional template](https://sendgrid.com/docs/User_Guide/Transactional_Templates/index.html). Following is the template content we used for testing. -Template ID (replace with your own): - -```text -13b8f94f-bcae-4ec6-b752-70d6cb59f932 -``` - Email Subject: ```text -<%subject%> +{{ subject }} ``` Template Body: @@ -24,13 +16,13 @@ Template Body: -Hello {{name}}, +Hello {{ name }},

I'm glad you are trying out the template feature!

<%body%>

-I hope you are having a great day in {{city}} :) +I hope you are having a great day in {{ city }} :)

@@ -39,15 +31,15 @@ I hope you are having a great day in {{city}} :) ```js const sgMail = require('@sendgrid/mail'); sgMail.setApiKey(process.env.SENDGRID_API_KEY); -sgMail.setSubstitutionWrappers('{{', '}}'); // Configure the substitution tag wrappers globally const msg = { to: 'recipient@example.org', from: 'sender@example.org', subject: 'Hello world', text: 'Hello plain world!', html: '

Hello HTML world!

', - templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932', - substitutions: { + templateId: 'd-f43daeeaef504760851f727007e0b5d0', + dynamic_template_data: { + subject: 'Testing Templates', name: 'Some One', city: 'Denver', }, @@ -55,12 +47,4 @@ const msg = { sgMail.send(msg); ``` -Alternatively, you may specify the substitution wrappers via the msg object as well. This will override any wrappers you may have configured globally. - -```js -const msg = { - ... - substitutionWrappers: ['{{', '}}'], - ... -}; -``` +There's no need to specify the substitution wrappers as it will assume that you're using [Handlebars](https://handlebarsjs.com/) templating by default.