Previewing templates
In the console
Open a template under Templates and the editor shows a live preview beside the fields. As you type it:
- detects every
{{placeholder}}across the subject, HTML and text, and lists the distinct names it found; - gives you a box per name to type a test value into;
- renders the subject, the HTML in an isolated frame, and the text, with those values substituted;
- shows a ready-made
POST /v1/sendsnippet carrying the template id and avariablesobject with the detected keys.
This is the fastest way to catch the failure that nothing else catches: leave a box empty and you see exactly what a recipient sees when your code forgets that key.
The preview applies the same substitution rule as the send path, including
HTML-escaping values in the HTML body, so a test value of <b>x</b> shows as
visible text there and as markup nowhere.
There is no preview endpoint
Nothing exposes “render this template with these variables and return the
result without sending”. POST /v1/templates and PUT /v1/templates/{id}
store, /v1/send renders and sends, and there is nothing in between.
If you want rendered output from a program, you have two options, and they are both honest:
Render it yourself. The rule is small enough to reimplement in a few lines, and reimplementing it is the only way to preview without a round trip:
const PLACEHOLDER = /\{\{\s*([\w.-]+)\s*\}\}/g;
const render = (tmpl, vars, escape) =>
(tmpl ?? '').replace(PLACEHOLDER, (_m, name) => {
const v = vars[name] ?? '';
return escape ? escapeHtml(v) : v;
});
Apply escaping to the html field only, not to subject or text, and match
it to ours exactly: five characters, with the apostrophe as ' and the
double quote as ". Be aware this is a copy, so if our rule ever changes,
yours does not follow.
Send it on a test key. Slower, involves a network call, and is the only method that shows you output produced by the same code that would have produced the real message. Testing rendered emails covers it.
Previewing in a real mail client
Neither method above tells you how the HTML looks in Outlook. For that you have to put a real message in front of a real client: send the template to an address you own on a live key and open it. Rendering in mail clients is not something any API response can answer.