Skip to content

Commit

Permalink
Merge pull request #731 from houssem-yahiaoui/master
Browse files Browse the repository at this point in the history
Updating Documentation | USER CASES
  • Loading branch information
thinkingserious authored Aug 28, 2018
2 parents 6a169ae + 8c275f0 commit 6f4058c
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 24 deletions.
1 change: 1 addition & 0 deletions use-cases/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
64 changes: 64 additions & 0 deletions use-cases/transactional-legacy-templates.md
Original file line number Diff line number Diff line change
@@ -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
<html>
<head>
<title></title>
</head>
<body>
Hello {{name}},
<br /><br/>
I'm glad you are trying out the template feature!
<br /><br/>
<%body%>
<br /><br/>
I hope you are having a great day in {{city}} :)
<br /><br/>
</body>
</html>
```

```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: '<p>Hello HTML world!</p>',
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: ['{{', '}}'],
...
};
```
32 changes: 8 additions & 24 deletions use-cases/transactional-templates.md
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -24,13 +16,13 @@ Template Body:
<title></title>
</head>
<body>
Hello {{name}},
Hello {{ name }},
<br /><br/>
I'm glad you are trying out the template feature!
<br /><br/>
<%body%>
<br /><br/>
I hope you are having a great day in {{city}} :)
I hope you are having a great day in {{ city }} :)
<br /><br/>
</body>
</html>
Expand All @@ -39,28 +31,20 @@ 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: '<p>Hello HTML world!</p>',
templateId: '13b8f94f-bcae-4ec6-b752-70d6cb59f932',
substitutions: {
templateId: 'd-f43daeeaef504760851f727007e0b5d0',
dynamic_template_data: {
subject: 'Testing Templates',
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: ['{{', '}}'],
...
};
```
There's no need to specify the substitution wrappers as it will assume that you're using [Handlebars](https://handlebarsjs.com/) templating by default.

0 comments on commit 6f4058c

Please sign in to comment.