> ## Documentation Index
> Fetch the complete documentation index at: https://docs.maqetin.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Templates

> Write the subject, preheader and HTML of an email, print contact values in it, preview it and send yourself a test.

A template is the subject, preheader and HTML of one email. A journey's **Send email** step sends it, and so does a transactional send through [`POST /v1/public/messages`](https://docs.maqetin.com/api-reference/send-message). You keep templates in the console under **Content**; any member can create, edit, preview, test and delete them.

## Create a template

**1. Open Content**

Click **Content**, then **Create template**.

**2. Fill in the fields**

Give it a **Name**, a **Subject**, an optional **Preheader** and the HTML of the email. Maqetin makes the plain-text part from the HTML.

**3. Save it**

Click **Save template**. Maqetin renders it once with sample values; a template that cannot be rendered is not saved, and the console says why.

Every save makes a new version, shown with its save time on the template's page. A send uses the version saved last when the email is made.

## Print values in a template

Write a value's name in double braces, in the subject, the preheader or the HTML.

```html theme={null}
<p>Hi {{default first_name "there"}},</p>
<p>Your order {{order.id}} came to {{order.total}}.</p>
```

| Value | What it holds |
| - | - |
| `first_name`, `last_name` | The contact's `firstName` and `lastName` |
| `firstName`, `lastName`, `phone`, `plan`, `country`, `timezone`, `locale` | The contact's standard traits, by their own names |
| Any custom trait | By its name, for example `{{company}}` |
| `email` | The address the email goes to |
| `user_id` | The contact's `userId`. Empty for a send to an address with no contact |
| The keys of `data` | The `data` object of a [transactional send](https://docs.maqetin.com/api-reference/send-message.md), at the top level: `data: { order: { id } }` prints as `{{order.id}}` |
| `event.<property>` | In a journey email: a property of the event that started the journey, such as `{{event.amount}}` |
| `contact.<value>` | In a journey email sent to another contact: the values of the contact in the journey, such as `{{contact.first_name}}` |

A missing value prints nothing.

| Tag | Use |
| - | - |
| `{{name}}` | Print a value. Reach into an object with a dot: `{{order.total}}` |
| `{{default name "fallback"}}` | Print the value, or the fallback when it is missing or empty |
| `{{#if name}}…{{else}}…{{/if}}` | Show a part only when a value is set |
| `{{#unless name}}…{{/unless}}` | Show a part only when a value is not set |
| `{{#each items}}…{{/each}}` | Repeat a part for each item of a list. Inside, `{{this}}` or `{{field}}` is the item |
| `{{#with order}}…{{/with}}` | Read the values of one object without repeating its name |

`{{name}}` in the HTML is HTML-escaped, so a value adds no markup. Triple braces, `{{{name}}}`, print unescaped: use them only for HTML you wrote yourself, never for a value a person can set. Values in the subject print as text. Partials are refused.

## The footer

Maqetin adds a footer to every email; the template cannot remove or change it. Every email carries the postal address of its [sending domain](https://docs.maqetin.com/messaging/sending-domains.md), and journey email also carries an **Unsubscribe** link. Email sent through the API carries the postal address only. See [Email](https://docs.maqetin.com/messaging/email.md).

## Preview and test

The template's page shows a preview of your edits, before you save them. Pick a contact under **Preview as** to render it with that contact's values, and switch between **HTML** and **Plain text**. The footer shows as "Your postal address appears here"; the real address and unsubscribe link are added when an email is made.

> [!NOTE]
>
> A preview has a contact and nothing else: `data` and `event.` values print empty. Use `default` for any value that may be missing.

**1. Save the template**

A test sends the saved version, without your unsaved edits.

**2. Click Send test**

Pick a verified domain under **Send from**. The test needs [sending approval](https://docs.maqetin.com/workspace/sending-approval.md).

**3. Check your inbox**

One test goes to your own sign-in address, and to nobody else.

## Use a template in a send

The template's id is shown in the header of its page. A journey's **Send email** step picks the template by name. A transactional send names it as `templateId`:

```ts Node theme={null}
import { MaqetinServer } from '@maqetin/sdk-js/server';

const mq = new MaqetinServer({ secretKey: process.env.MAQETIN_SECRET_KEY });
const { messageId } = await mq.messages.send({
  channel: 'email',
  templateId: 'tpl_receipt',
  to: { userId: 'u_42' }, // or { email: 'guest@example.com' }
  from: 'Harbour Money <receipts@mail.harbour-money.example>',
  data: { order: { id: 'o_42', total: 12.5 } },
  idempotencyKey: 'order-42:receipt',
});
```

```bash cURL theme={null}
curl https://api.maqetin.com/v1/public/messages \
  -H 'Authorization: Bearer mq_sec_…' \
  -H 'Content-Type: application/json' \
  -H 'Idempotency-Key: order-42:receipt' \
  -d '{
  "channel": "email",
  "templateId": "tpl_receipt",
  "to": { "email": "ada@example.com" },
  "from": "Receipts <receipts@mail.harbour-money.example>",
  "subject": "Your receipt",
  "data": { "order": { "id": "o_42", "total": 12.5 } }
}'
```

The example prints `{{order.id}}` and `{{order.total}}`.

## Find and delete templates

**Content** lists your templates newest first. **Find a template** matches the start of a template name, in any case.

**Delete template** removes a template and every version of its HTML for good. It is refused while a journey that is not archived, a paused one included, still uses it in its running version or in an older version that contacts are still in. Archive the journey, or publish a version without the template and wait until nobody is left on the older versions.

## Limits

| Limit | Value |
| - | - |
| **Name** | 100 characters |
| **Subject** | One line, 300 characters |
| **Preheader (optional)** | 200 characters. Most inboxes show it after the subject |
| HTML | 200,000 bytes. One save carries about 100 KB at most, so keep the HTML under that |
| Tags in a template | 1,000 |
| Rendered email, values in | Subject 300 characters, preheader 1,000, body 300,000 bytes. An email over these is not sent |
| `data` in a send | 16 KB as JSON |
| Tests | 5 in 10 minutes |

## Good to know

* When two values share a name, `data` wins over a trait, and a trait wins over the `first_name` and `last_name` aliases. Nothing overrides `email` or `user_id`.
* A test has no contact behind it: only `email` and `user_id` hold values; traits, `data` and `event.` values print empty.


## Related topics

- [Journeys](https://docs.maqetin.com/messaging/journeys.md)
- [Send a message](https://docs.maqetin.com/api-reference/send-message.md)
- [JavaScript SDK](https://docs.maqetin.com/sdk/javascript.md)
- [Sending approval](https://docs.maqetin.com/workspace/sending-approval.md)
- [Email](https://docs.maqetin.com/messaging/email.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.