Skip to content
Docs
/
Guides
/
Templates with variables

Templates with variables

Personalization is the key to the success of your email marketing. With Plunk you can easily create and send emails with variables that will be replaced with data on the go.

Adding data to users

Before you can add data to your emails, we need to add that data to our users. For this we will make use of the optional data parameter when sending events.

const res = await fetch('https://api.useplunk.com/v1', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer API_KEY",
    },
    body: JSON.stringify({
        "event": "new-project",
        "email": "hello@useplunk.com",
        "data": {
            "company": "Plunk"
        }
    }),
});

Plunk will automatically keep track of the data you add to your users, keeping it updated as events are sent. You can add as many variables to a user as you want.

Important notes

  • Variables are case sensitive.
  • Variables can not be versioned, meaning Plunk will replace the value of a variable every time it is sent a different value.

Adding a variable to your emails

When creating a template, you can use the double curly braces {{variable}} to add variables to both the subject and the body of the email.

<h1>Hello {{company}}</h1>

Plunk will automatically replace the variable with the data attached to the user, if it exists.

Special cases

Lists

You can add lists to users by pushing an array of values to the data parameter.

const res = await fetch('https://api.useplunk.com/v1', {
    method: "POST",
    headers: {
        "Content-Type": "application/json",
        "Authorization": "Bearer API_KEY",
    },
    body: JSON.stringify({
        "event": "new-project",
        "email": "hello@useplunk.com",
        "data": {
            "list": ["item 1", "item 2", "item 3"]
        }
    }),
});

Array values will automatically be rendered as lists in templates and campaigns.

Last updated on August 27, 2022