-
Notifications
You must be signed in to change notification settings - Fork 723
Adds support for dynamic template data in personalizations #593
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -66,6 +66,38 @@ print(response.body) | |
| print(response.headers) | ||
| ``` | ||
|
|
||
| ### With dynamic templates | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Regarding updates for rest of file: this is left on purpose, as old template system is still in place, as well as code to support it. So, I guess we still need documentation for it. Or I'm missing the point |
||
|
|
||
| Sendgrid dynamic templates let you leverage power of [handlebars](https://handlebarsjs.com/) | ||
| syntax to easily manage complex dynamic content in transactional emails. | ||
|
|
||
| To check this example snippet, create | ||
| [transactional email template](https://sendgrid.com/dynamic_templates) with code like | ||
| ```html | ||
| <p>Hello, {{name}}! Your current balance is {{balance}}<p> | ||
| ``` | ||
|
|
||
| Than send email based on it, providing context for substitutions: | ||
| ```python | ||
| from sendgrid import SendGridAPIClient | ||
| from sendgrid.helpers.mail import Email, Personalization | ||
|
|
||
|
|
||
| sg = SendGridAPIClient(apikey='SG.your-api-key') | ||
|
|
||
| mail = Mail() | ||
| mail.from_email='templates@example.com' | ||
| mail.template_id = 'd-your-dynamic-template-uid' | ||
| p = Personalization() | ||
| p.add_to(Email('user@example.com')) | ||
| p.dynamic_template_data = {'name': 'Bob', 'balance': 42} | ||
| mail.add_personalization(p) | ||
|
|
||
| sg.client.mail.send.post(request_body=mail.get()) | ||
| ``` | ||
|
|
||
| Read more about dynamic templates in [docs](https://sendgrid.com/docs/User_Guide/Transactional_Templates/how_to_send_an_email_with_transactional_templates.html) | ||
|
|
||
| ## Without Mail Helper Class | ||
|
|
||
| ```python | ||
|
|
@@ -113,4 +145,4 @@ except urllib.HTTPError as e: | |
| print(response.status_code) | ||
| print(response.body) | ||
| print(response.headers) | ||
| ``` | ||
| ``` | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Typo: sill → will
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks! Fixed :)