Introduction
Turn a named template and a props object into an HTML string. The frontend renders it, and your code delivers it as an email, a file or a response.
Overview
The html-render domain of @antelopejs/interface-dms turns a named template and a props object into an HTML string. You declare a template once with RegisterHtmlTemplate. It records the name in a process-wide registry and returns a typed reference. Pass that reference to GenerateHtml to get the rendered HTML.
The backend process does not render anything itself. GenerateHtml sends an HTTP POST to the dashboard's /api/html/render, or to htmlRender.renderEndpoint when the DMS configures one, authenticated with a signed service token, and returns the HTML the endpoint sends back. The backend owns the template names and the props types. The markup lives with the renderer behind that endpoint.
The interface produces HTML and nothing else. Your code delivers that HTML, as a transactional email, a file or a response body.
Everything below is exported from one subpath:
import {
GenerateHtml,
GetAllHtmlTemplates,
GetHtmlTemplate,
RegisterHtmlTemplate,
} from "@antelopejs/interface-dms/html-render";
import type {
HtmlRenderConfig,
HtmlTemplateInfo,
HtmlTemplateRef,
} from "@antelopejs/interface-dms/html-render";
What the domain provides
- A named template registry.
RegisterHtmlTemplaterecords a template name at import time, so the whole process shares one list of renderable templates. - Documented props. The type parameter of
RegisterHtmlTemplatetravels with the returnedHtmlTemplateRef, so the reference records which props the template expects. - Rendering over HTTP.
GenerateHtmlcalls the configured render endpoint with a signed service token and resolves to the returned HTML string. - Registry lookups.
GetHtmlTemplateandGetAllHtmlTemplatesread back what is registered, one name at a time or all at once. - Endpoint and token settings.
HtmlRenderConfigtypes thehtmlRenderblock of the DMS module configuration: the endpoint URL, the signing secret and the token lifetime.
Dependencies
This interface relies on one other AntelopeJS package:
@antelopejs/interface-coreprovidesInterfaceFunctionandRegisteringProxy, the two helpers the interface is built from.
Quick start
Register a template next to the code that uses it, then render it with props. Registration runs when the module is imported, so keep the reference in module scope.
import {
GenerateHtml,
RegisterHtmlTemplate,
} from "@antelopejs/interface-dms/html-render";
interface WelcomeProps {
userName: string;
activationLink: string;
}
const WelcomeTemplate = RegisterHtmlTemplate<WelcomeProps>("EmailWelcome");
export async function buildWelcomeHtml(
userName: string,
activationLink: string,
): Promise<string> {
return GenerateHtml(WelcomeTemplate, { userName, activationLink });
}
GenerateHtml needs a reachable render endpoint, so call it from request or job code, never at import time.
RegisterHtmlTemplate
Registers a template name and returns the reference you render with.
function RegisterHtmlTemplate<TProps = unknown>(
name: string,
): HtmlTemplateRef<TProps>;
| Parameter | Description |
|---|---|
name | The template identifier. The registry stores the template under this key, and GenerateHtml sends it to the render endpoint as templateName. |
The type parameter TProps declares the props the template expects. The returned HtmlTemplateRef carries it as a record of the template's shape. GenerateHtml takes its props argument as unknown, so the compiler does not check the props against TProps at the call site. Without TProps, the reference's props type is unknown.
import { RegisterHtmlTemplate } from "@antelopejs/interface-dms/html-render";
interface InvoiceProps {
invoiceNumber: string;
amount: string;
dueDate: string;
}
export const InvoiceTemplate =
RegisterHtmlTemplate<InvoiceProps>("EmailInvoice");
The registry is keyed by name, so registering an existing name replaces the earlier entry. The DMS registers seven names for its own emails, listed in Built-in emails. Give your templates other names.
Call RegisterHtmlTemplate at module scope, in a file your module imports during startup. The returned reference is a plain object, so export it from that file to share it.
The subpath also exports an internal namespace that holds the registering proxy this function writes through. It is marked @internal. Register through RegisterHtmlTemplate instead.
GenerateHtml
Renders a registered template and resolves to the resulting HTML.
const GenerateHtml: (
template: HtmlTemplateRef<unknown>,
props: unknown,
language?: string,
) => Promise<string>;
| Parameter | Description |
|---|---|
template | The reference returned by RegisterHtmlTemplate. Pass the reference, not the name string. |
props | The data the template renders with, serialized into the request body. The DMS render endpoint expects a JSON object and answers 400 to anything else, so keep the props type an object shape. The parameter is typed unknown, so the compiler does not enforce the props type recorded on the reference. Match it yourself. |
language | Optional. The language to render in, sent in the x-content-language header. The DMS render endpoint renders in the language its first two letters name when a locale file exists for it, and in English otherwise. Without it, the template renders in English. |
import {
GenerateHtml,
RegisterHtmlTemplate,
} from "@antelopejs/interface-dms/html-render";
interface InvoiceProps {
invoiceNumber: string;
amount: string;
dueDate: string;
}
const InvoiceTemplate = RegisterHtmlTemplate<InvoiceProps>("EmailInvoice");
export async function renderInvoice(
invoiceNumber: string,
language: string,
): Promise<string> {
return GenerateHtml(
InvoiceTemplate,
{ invoiceNumber, amount: "240.00 EUR", dueDate: "2026-08-15" },
language,
);
}
The call sends { templateName, props } as JSON to the render endpoint. It carries a service token signed with htmlRender.serviceSecret in the x-dms-service-token header, and it reads the html field of the JSON response.
GenerateHtml does not look the name up in the registry before the call. It sends whatever name the reference carries. When the render endpoint does not know the name, the promise rejects. The backend runs no missing-template check of its own.
The promise rejects in three cases:
- On a non-2xx response, with an
Errorwhose message starts withFailed to render HTML template:. The rest is themessagestring of the response body, else itserrorstring, else itsstatusMessage, elseHTTP <status>. The DMS render endpoint answers401withInvalid service token,400withInvalid request body, and404withTemplate "<name>" not found or render failed. - On a 2xx response without an
htmlstring, with the messageFailed to render HTML template: the render service answered no html. - When the endpoint is unreachable, with the
fetcherror itself, without that prefix.
To keep a failed render from stopping the surrounding operation, catch the rejection:
import { Logging } from "@antelopejs/interface-core/logging";
import {
GenerateHtml,
RegisterHtmlTemplate,
} from "@antelopejs/interface-dms/html-render";
interface InvoiceProps {
invoiceNumber: string;
amount: string;
dueDate: string;
}
const InvoiceTemplate = RegisterHtmlTemplate<InvoiceProps>("EmailInvoice");
export async function renderInvoiceOrNull(
invoiceNumber: string,
): Promise<string | null> {
try {
return await GenerateHtml(InvoiceTemplate, {
invoiceNumber,
amount: "240.00 EUR",
dueDate: "2026-08-15",
});
} catch (error) {
const reason = error instanceof Error ? error.message : String(error);
Logging.Error(`Invoice render failed: ${reason}`);
return null;
}
}
GetHtmlTemplate
Looks one template up in the registry.
const GetHtmlTemplate: (key: string) => Promise<HtmlTemplateInfo | undefined>;
| Parameter | Description |
|---|---|
key | The name the template was registered under. |
Resolves to the HtmlTemplateInfo stored for that name, or to undefined when nothing is registered under it.
import { GetHtmlTemplate } from "@antelopejs/interface-dms/html-render";
export async function isTemplateRegistered(name: string): Promise<boolean> {
return (await GetHtmlTemplate(name)) !== undefined;
}
GetAllHtmlTemplates
Resolves to every registered template, keyed by name.
const GetAllHtmlTemplates: () => Promise<Record<string, HtmlTemplateInfo>>;
import { GetAllHtmlTemplates } from "@antelopejs/interface-dms/html-render";
export async function listTemplateNames(): Promise<string[]> {
return Object.keys(await GetAllHtmlTemplates());
}
The DMS builds a new object from the registry on each call, so changing the result does not change what is registered. Registration happens as modules are imported, so call this function after startup to get the complete set.
HtmlTemplateInfo
What the registry stores for each template, and what GetHtmlTemplate and GetAllHtmlTemplates resolve to.
| Field | Type | Description |
|---|---|---|
name | string | The registered template name. |
import type { HtmlTemplateInfo } from "@antelopejs/interface-dms/html-render";
import { GetAllHtmlTemplates } from "@antelopejs/interface-dms/html-render";
export async function describeTemplates(): Promise<string> {
const templates: Record<string, HtmlTemplateInfo> =
await GetAllHtmlTemplates();
return Object.values(templates)
.map((info) => info.name)
.join(", ");
}
HtmlTemplateRef
The reference RegisterHtmlTemplate returns and GenerateHtml accepts.
| Field | Type | Description |
|---|---|---|
name | string | The template name sent to the render endpoint. |
_propsType | TProps | undefined | Optional field that only carries the props type. RegisterHtmlTemplate never sets it. Do not read it. |
To keep the props type visible in the declarations of a module that collects references, annotate the reference:
import type { HtmlTemplateRef } from "@antelopejs/interface-dms/html-render";
import { RegisterHtmlTemplate } from "@antelopejs/interface-dms/html-render";
interface AlertProps {
title: string;
body: string;
}
export const AlertTemplate: HtmlTemplateRef<AlertProps> =
RegisterHtmlTemplate<AlertProps>("EmailAlert");
HtmlRenderConfig
Types the htmlRender block of the DMS module configuration in antelope.config.ts.
| Option | Type | Description |
|---|---|---|
renderEndpoint | string | The absolute URL GenerateHtml posts to. Default /api/html/render on the dashboard's current origin: the one ajs dms dev serves, else the DMS's clientBaseUrl. |
serviceSecret | string | The secret that signs the service token of each render call. Default "dev". The DMS refuses a production start when the value is empty or "dev". |
serviceTokenLifetime | number | The lifetime of that service token, in milliseconds. The frontend render server rejects a token valid for more than five minutes. Default 300000 (five minutes). |
The DMS merges the block you supply over those defaults, so a configuration needs only the keys it changes. In this example, envOverrides reads the secret from DMS_HTML_RENDER_SECRET at start:
import { defineConfig } from "@antelopejs/interface-core/config";
export default defineConfig({
name: "acme-admin",
envOverrides: {
DMS_HTML_RENDER_SECRET: "modules.dms.config.htmlRender.serviceSecret",
},
modules: {
dms: {
source: {
type: "package",
package: "@antelopejs/dms",
version: "latest",
},
config: {
htmlRender: {
renderEndpoint: "https://admin.example.com/api/html/render",
},
},
},
},
});
Configuration lists this block with the other DMS options.
Email layout
The DMS ships the frame of its own emails as EmailLayout. A module's email template, registered through its dms.email.ts, can reuse it. The frame draws the branding logo and a white card that holds an optional heading, the content, and a footer slot below a separator.
<script setup lang="ts">
import EmailLayout from "#dms-layout/app/emails/components/EmailLayout.vue";
defineProps<{ subject: string; preheader: string; locale: string }>();
</script>
<template>
<EmailLayout
:lang="locale"
:preheader="preheader"
:divider="false"
public-logo-only
>
<template #head>
<title>{{ subject }}</title>
</template>
<EText>Your order has shipped.</EText>
<template #footer>
<EText>Acme Inc.</EText>
</template>
</EmailLayout>
</template>
| Prop | Type | Description |
|---|---|---|
title | string (optional) | Drawn as the h1 heading. Without it, the email has no heading. |
lang | string (optional) | The lang of the document. Default "en". |
preheader | string (optional) | The inbox preview text, hidden in the body. |
divider | boolean (optional) | Draws the separator above the footer slot. Default true. |
logoAlt | string (optional) | The alternative text of the logo. Default "Logo". Pass "" for a decorative logo. |
publicLogoOnly | boolean (optional) | Leaves the logo out unless a mail client can load it. The rules follow the table. Default false. |
The head slot adds elements to the document head, such as a <title> or a viewport <meta>.
The logo is branding.logo.email.light from the app config, or branding.logo.default.light when no email logo is set. A logo path that starts with / is made absolute against public.dms.clientBaseUrl, or against the DMS_CLIENT_BASE_URL environment variable of the frontend server when it is set.
A recipient's mail client fetches the logo from the internet, and Gmail and Outlook refuse SVG. With publicLogoOnly, the layout leaves the logo out instead of drawing a broken image when the logo:
- is an SVG,
- does not resolve to an
httporhttpsURL, or - is served from a host a mail client cannot reach:
localhost, a*.localhost,*.localor*.internalname, or a loopback, private or link-local address.
Set a logo that is not an SVG, and a public clientBaseUrl, for the logo to show.
A branding.logo.email.dark goes through the same rules. When it differs from the light logo, the layout offers it to mail clients in dark mode. The logo is then drawn as <picture><source media="(prefers-color-scheme: dark)" srcset="…"><img …></picture>, and a client that ignores the source draws the light image. The layout has no dark styles of its own. The card stays white on its pale grey background (#f6f9fc) in both modes, and only the logo changes.
#dms-layout/app/emails/components/index exports the same check as emailLogoUrl(logoPath, clientBaseUrl), for a template that draws its own header. It returns the absolute URL, or "" when the logo fails the rules.
A rendered custom digest
The playground's EmailPlaygroundDigest template (packages/dms/playground/frontend-vue/app/emails/EmailPlaygroundDigest.vue) reuses this layout with a preheader, :divider="false" and public-logo-only. Rendered in English for a user named Alex Morgan, it contains:
- the heading Your playground digest,
- the greeting
Hello Alex Morgan,, - the line
<count> things happened in the playground since your last visit., with the same count in the hidden preheader, - the footer
Sent by the DMS playground's emails demo., with no separator above it.
With the default SVG logo, the email has no logo at all. With a PNG light logo and a different PNG dark logo set in the app config, a mail client in light mode draws the light logo above the heading, and a client that follows dark mode draws the dark one. The card and the text keep the same colors in both modes. A local render does not show whether a recipient's mail client can fetch the logo from the internet.
Send rendered HTML as email
Rendering and sending are separate steps. Render with GenerateHtml, then pass the string to the AntelopeJS email interface, @antelopejs/interface-email. That interface needs an implementing module, such as @antelopejs/nodemailer, loaded in your project configuration.
import { Send } from "@antelopejs/interface-email";
import {
GenerateHtml,
RegisterHtmlTemplate,
} from "@antelopejs/interface-dms/html-render";
interface ReceiptProps {
userName: string;
orderId: string;
}
const ReceiptTemplate = RegisterHtmlTemplate<ReceiptProps>("EmailReceipt");
export async function sendReceipt(
email: string,
userName: string,
orderId: string,
): Promise<void> {
const html = await GenerateHtml(ReceiptTemplate, { userName, orderId });
const result = await Send({
to: email,
subject: `Your receipt for order ${orderId}`,
html,
});
if (!result.success) {
throw new Error(`Failed to send receipt: ${result.error?.message}`);
}
}
The DMS sends its own account emails the same way, and the two steps fail apart. A rejected GenerateHtml means the DMS never produced the HTML. A success: false response from Send means the HTML exists but the email was not delivered.