# Create email templates

Write an email once with variables such as the order number, publish it, and reuse it from your website, broadcasts and automations.

A template is an email your team writes once and sends many times: an order confirmation, a shipping notice, a welcome email. Marketers edit the wording in the dashboard while your website or app keeps sending the same template, with the order number and total filled in for each customer. Broadcasts and automations can start from templates too.

Creating and editing templates needs the **Work** level on the Email module.

## Create a template

1. Open **Email → Templates** and click **New template**.
2. Fill in the defaults at the top. Each send can override them:
   - **Name**: for your team, for example "Order confirmation".
   - **Alias**: a short name such as `order-confirmation` that your developer uses instead of the template id. Lowercase letters, digits, `-` and `_`.
   - **From**: an address on a verified domain, for example `Mộc Hương Tea <don-hang@mochuong.vn>`.
   - **Subject**, **Reply-To** and **Folder** (to group templates in the list).
3. Write the email in the **HTML** tab. Check it in **Preview**, which fills each variable with its fallback.
4. Leave **Plain text** empty unless you want to write it yourself: Ha Tang generates it from the HTML. A plain-text part helps deliverability.
5. Click **Save**. The template is a **Draft**.

![The template editor: defaults, HTML, variables and the publish actions](https://hatang.dev/help/img/en/email/template-editor.webp)

## Use variables

Variables are written with three braces: `{{{order_id}}}`. Add a default after a vertical bar for when no value is sent: `{{{customer_name|bạn}}}`.

1. Under **Variables**, click **Add variable** for each one, or **Declare all** to add every variable Ha Tang finds in the subject and body.
2. Give each a type, **string** or **number**, and optionally a **Fallback**.

Rules to know:

- Every variable used in the subject or body must be declared before you can publish. Missing ones are listed under **Not declared**.
- When a send has no value for a variable, Ha Tang uses the inline default, then the fallback. If there is neither, the send is refused and nothing goes out, so give a fallback to any variable your website might leave out.
- These are filled automatically when sending to contacts and need no declaring: `{{{FIRST_NAME}}}`, `{{{LAST_NAME}}}`, `{{{EMAIL}}}`, `{{{UNSUBSCRIBE_URL}}}`, and contact properties as `{{{contact.city}}}`.
- Values are made safe for HTML automatically, so a customer name cannot break your layout.

## Check, test and publish

1. Click **Check links**. Ha Tang flags links that are empty, only `#`, on a placeholder domain (`example.com`, `yourdomain.com`, `localhost`…), not `http(s)`, unreachable, or answering with an error page.
2. Click **Send test** to receive the current draft in your own mailbox, with `[Test]` before the subject. Variables show their fallback, or their name in brackets (`[order_id]`) when they have none. The draft needs a **From** address for this.
3. Click **Publish**. Link problems hold publishing back until you fix them or choose **Publish anyway**.

Only the published version is sent. You can keep editing: the API, broadcasts and automations keep using the last published version until you publish again, and the list shows **Unpublished changes** in the meantime. This lets you prepare a new wording without changing what customers receive today.

**Duplicate** copies the template into a new draft, for example to make a variant for another product line.

## Where templates are used

| Where | How |
|---|---|
| Your website or app | Your developer sends the template's id or alias with the variable values. See the [templates guide in the developer hub](https://hatang.dev/docs/guides/email/templates) |
| Broadcasts | **Start from a template** copies a published template into the broadcast. Later changes to the template do not change a broadcast already created. See [Send a broadcast](https://hatang.dev/help/email/broadcasts) |
| Automations | Each **Send email** step sends a published template. See [Automations](https://hatang.dev/help/email/automations) |

## Troubleshooting

| Symptom | Cause | What to do |
|---|---|---|
| **Publish** fails with an undeclared variable | The content uses a variable that is not in **Variables** | Click **Declare all**, then publish |
| A send fails with "is not published yet" | The template has never been published | Publish it |
| A send fails with "Missing value for template variable" | A variable got no value and has no default or fallback | Add a fallback, or ask your developer to send the value |
| Customers still get the old wording | The changes are saved but not published | Publish; the list shows **Unpublished changes** until you do |
| An automation cannot be enabled | One of its templates is not published, or has no **From** | Publish the template and set **From** |
