Dynamic Email Templates

Sendwithus supports a large subset of the Jinja templating language. Below are examples for some common templating use-cases.

Simple variable replacement can be achieved using the following syntax.

API Call

Template HTML

Rendered HTML

Hello Chuck


sendwithus!

Conditional syntax can be used to include/exclude email content based on data passed into API calls.

API Call

Template HTML

Rendered HTML

Sign up today and get 30% off!
Refer your friends!

The Sendwithus API accepts JSON arrays for email data. These arrays can be iterated over inside the HTML template.

API Call

Template HTML

Rendered HTML

Your Invoice:

  • Item One: $5.99
  • Item Two: $10.00

Most of your HTML needs can be met in our template editor or by using Snippets. If you are using user-generated HTML and you need to pass raw HTML as a variable, you’ll need to escape it with jinja safe filters or autoescape tags.

API Call

Template HTML

Rendered HTML

Hello

Lorem impsum

Click here.

The following variables are provided by Sendwithus and are available in every template.

Usage Description Example
{{ swu.recipient.address }} Recipient’s email address danny.tanner@email.com
{{ swu.recipient.name }} Recipient’s name (if provided) Danny Tanner
{{ swu.sender.address }} Sending address notifications@yourdomain.com
{{ swu.sender.name }} Sending name AwesomeProduct
{{ swu.sender.reply_to }} Sending Reply-To address (if provided) no-reply@yourdomain.com
{{ swu.template.id }} Template API ID tem_2OASY7df92
{{ swu.template.locale }} Template Locale en-US
{{ swu.template.name }} Template Name Welcome Email
{{ swu.template.version_id }} Template Version Id ver_123453sdf30
{{ swu.template.version_name }} Template Version Name Version A – Friendly Subject Line
{{ swu.webview_url }} URL to view this email in a browser
{{ swu.log_id }} Send receipt ID log_1234asdf9876lkjh

Advanced Jinja for html wizards

The following example illustrates how the round and format filters can be used to display numbers.

API Call

Template HTML

Rendered HTML

Numbers:

  • 44.0
  • 44.5
  • 44
  • $44.45

The following example illustrates how to use our custom Jinja filters to achieve date formatting of both timestamps and ISO 8601 date strings. For a rundown on formatting rules see the python docs

API Call

Template HTML

Rendered HTML

ISO:

Tue, February 17

Timestamp:

Tue, February 17

Below we show how to use default to gracefully handle empty variables. The filter wordwrap is shown as an example of how to format a plain text email so it looks good, no matter the size.

API Call

Template HTML

Rendered HTML

Hi there,
This
be
some
words

Let jinja do the CSS work for you! The example below uses the loop control variable loop.cycle to alternate between CSS classes to make a striped table.

API Call

Template HTML

Rendered HTML

$12.00
$3.00
$20.00
$42.00