Templates and variables
Design an email once, publish it, and send it from your app by alias with values such as a name, a link or a code.
Instead of building HTML in your code, design the email in Cresca, mark the parts your app fills in, and publish it. Your app then sends only the template alias and the values.
Variables
Mark a value with triple braces: {{{RESET_LINK}}}. Variables can appear in the HTML, the plain-text version and the subject.
- Names use letters, numbers and underscores, up to 50 characters. Upper case is the convention.
- Each variable is a
string(up to 2,000 characters) or anumber, and can have a fallback value used when a send leaves it out. - A template can have up to 50 variables.
FIRST_NAME,LAST_NAME,EMAILandUNSUBSCRIBE_URLare reserved.
Values are HTML-escaped in the HTML body, so a name like <b>Ana</b> is shown as text and can never change your email's markup. In the text version values are inserted as-is, and line breaks are removed from the subject.
Draft and published versions
Editing a template changes its draft only. Sends always use the published version, so you can work on a change without affecting live email. Sending a template that has never been published fails with 422 validation_error: "This template has not been published yet. Publish it before sending." Publishing creates the next version number (1, 2, 3...). Placeholders in the draft that you have not declared are added as string variables without a fallback when you publish. Variables also work in the preview text.
Build it in the editor
- Open Transactional → Templates and click Create template. Start blank, or choose Import HTML to paste or drop an existing email.
- Choose the sender, write the subject and, if you like, a Reply-To address and preview text. The alias is how your app picks the template.
- Write the email. Type
/for blocks (headings, buttons, images, columns, dividers and more) and{{to add a variable. A button link or an image can be a variable too. - In the Variables panel, give optional values a fallback. A warning marks variables every send must include. Styles sets the background, link and button colours and the content width.
- Changes save automatically (or press
Cmd/Ctrl + S). Click Test email to send the draft to up to 5 addresses. Fill in the variables one by one or paste them as JSON, the same object your app sends intemplate.variables. Test emails count toward your monthly allowance. - Click Publish. Cresca checks the template (sender, subject, empty body, variables), then you slide to publish.
Every publish is kept in Version history (the ⋯ menu), with who published it and when. Restoring a version replaces the draft; publish it to make it live again.
You can also create and publish templates with the Templates API.
Send with a template
Pass the template id or alias and the variables instead of html and text:
curl -X POST 'https://api.cresca.xyz/api/v1/emails' \
-H 'Authorization: Bearer cr_live_xxxxxxxxx' \
-H 'Content-Type: application/json' \
-d '{
"to": "user@example.com",
"template": {
"id": "password-reset",
"variables": {
"NAME": "Ana",
"RESET_LINK": "https://acme.com/reset?token=abc"
}
}
}'| Field | Comes from |
|---|---|
html | The published template, with variables filled in. |
text | The template’s text version, or generated from the HTML. |
subject | Your request if given, otherwise the template’s default subject. |
from | Your request if given, otherwise the template’s default sender. |
reply_to | Your request, else the template, else the sender’s Reply-To. |
If a variable has no value and no fallback, the email is not sent and the API returns 422 validation_error naming the missing variables.