Dynamic data with template props

In the real world, emails are not just static and that's when template props come in handy. Template props are basically variables that allow you to put dynamic data in your email templates.

  • Template props can be used in any no-code editor's element.
  • To define a template prop, use {} curly brackets.

For example, in a password reset email template, you specify the URL of a button to {url} or {passwordResetUrl} or {password_reset_url} depending on your preference.

Now when sending the password reset email template, the template expects you to supply url (or whatever name you used) inside of templateProps object parameter.

This is how you send a template with templateProps:

const configureSidemail = require("sidemail");
const sidemail = configureSidemail({ apiKey: "replace-with-your-api-key" });
  
const response = await sidemail.sendEmail({
	toAddress: "user@email.com",
	fromAddress: "you@example.com",
	fromName: "Your app",
	templateName: "Password reset",
	templateProps: {
		"url": "https://reset.me/123"
	}
});

When no corresponding template prop name is found inside of templateProps, the template prop is left as is, just the curly brackets {} are removed.

Use-cases for template props

Here are a few ideas of how you can utilize template props:

  • to personalize an email with user's first name, eg., {firstName} becomes Patrik if templateProps look like this:
{ "firstName": "Patrik" }
  • to include unique typically auto-generated URLs (password reset, login link), eg., {sso_url} becomes https://login.me/in?token=123 if templateProps look like this:
{ "sso_url": "https://login.me/in?token=123" }
  • show the charged amount for your service on a receipt, eg., {charged-price} becomes $249 if templateProps look like this:
{ "charged-price": "$249" }

Gotchas

templateProps object parameter expects the values of template props to be string. Make sure you convert numbers to strings, otherwise, Sidemail will return parameters-invalid error.

Data for chart element and iteration group are exceptions.