Skip to content

Custom templates

A custom template is an edition template your organization writes and owns. It lays out an edition the way the library’s default and cut templates do, in your own design. You write it in React Email with the @edgekitcloud/email package (Install the packages), build it into one JavaScript file, the template bundle, and push it. A variant then uses it as custom:<name>.

A template is a pure function: an edition goes in, HTML comes out. EdgeKit runs it in an isolated sandbox with no network access, no secrets and no recipient data. Everything that varies per recipient, and everything EdgeKit guarantees about an email, happens after your code returns.

What a template receives and returns is a numbered contract. This page describes contract 2. The major version of @edgekitcloud/email is the contract number, so every 2.x release describes the same input and output. Contract 2 adds direct-sold ad creatives to contract 1. A template built on 1.x still renders, on contract 1, until contract 1’s support ends.

Field What it is
edition.slots The edition’s slots, in order, each stack slot replaced by its children.
edition.sendAt The send time as an ISO 8601 string, or null in an edition preview that has no send time.
edition.timezone The schedule’s IANA time zone, for reading sendAt. null means UTC.
edition.publicationName The publication’s name, for a page title or header. Absent or null in a fixture.
props The variant’s template props, as saved. Your template validates them.
locale The publication’s locale, such as en or en-GB.
brand The publication’s brand, else its site’s, or null when neither has one.

Each slot has a kind, its position (its 0-based place in the edition), a title or null, and the blockKey and blockProps it was set up with, so your template can lay out each block its own way. A child of a stack slot also has stack, the stack slot’s key, so your template can frame the children; no other slot has it. Then, by kind:

  • rich_text: content, rich text as Portable Text blocks. A block is a paragraph, a heading (h1 to h5), a quote or a list item, and its spans carry bold, italic, underline and link marks. A block with _type: 'image' is an image between paragraphs, shaped as an image slot’s image below. No HTML.
  • feed and curated: items, each with a headline, a summary or null, a link and an image (url, alt and credit) or null. Each image is sized at twice the width that EdgeKit’s block with the same key shows it at. credit comes from your CMS, such as a wire photographer’s credit, and is null on an image an editor picked. An item can also carry its section (its section on the publication’s site, the primary one when your CMS names one), its authors (each a name and an imageUrl, an https URL or null, in CMS order) and publishedAt (an ISO 8601 string: the CMS’s display date, else its first publication). Any of these four can be absent or null, so your template has to render without them.
  • ad: an ad slot and its creative. When a direct-sold creative fills the slot, creative holds it, adProvider is null, units is empty and pixels is 0. When your ad network’s tag fills it, creative is null, and the slot has its adProvider, its units (each a width, a height or null, and alt) and pixels, how many tracking images it has. A tag carries no URL: <AdUnit> and <AdPixels> write them. The web gets an ad slot only when a creative fills it.
  • image: an image slot, its image, its href, the link or null, and its item: the story it links to, or null. An item has a feed item’s fields without image; href is its link, read when the email renders. An image has a url (https), alt text (empty on a decorative image), and a width and height in pixels or null when not known. A picked image is 1,120 pixels wide, or narrower when its original is: EdgeKit’s blocks show it at most 560 pixels wide, its own width when narrower. A slot with no image picked is not in the edition.

A brand has a name, a logo URL or null, colors (primary, background and text, each #rrggbb when set), a font (sans, serif, mono or null), a footerAddress with its line breaks, and up to ten socialLinks.

A creative is { adType, fields }: its ad type’s key, and its values by field key. Your template lays it out like any other content. The values arrive as they are, with no EdgeKit tokens, because a creative holds no recipient’s data. So a creative also appears in the web archive and the plain-text version.

Field type Value
image An image, shaped as an image slot’s image.
text A string, up to 500 characters.
rich_text Portable Text, shaped as a rich_text slot’s content.
url The https URL, a string.
content_item { href, item }: the story’s link, and the story as an image slot’s item, read at the render.

An optional field left empty is absent from fields, and so is a content_item whose story is no longer on your site. Your template has to render without them.

A template receives a creative only of an ad type it lists in adTypes (see Write a template). A slot takes one ad type, and a deploy is refused while a variant’s template does not render the ad type of one of its publication’s ad slots. EdgeKit’s templates render EdgeKit’s four ad types; your organization’s own render only in your custom template.

import type { AdCreative, MediaImage, StoryLink } from '@edgekitcloud/email';
import { Img, Link, Section, Text } from 'react-email';
// `partner-spotlight` is an ad type of your organization's: logo (image), tagline (text), link (url),
// feature (content_item).
function Spotlight({ creative }: { creative: AdCreative }) {
const { logo, tagline, link, feature } = creative.fields as {
logo?: MediaImage;
tagline?: string;
link?: string;
feature?: StoryLink;
};
return (
<Section>
{logo && (
<Link href={link}>
<Img src={logo.url} alt={logo.alt} width={120} />
</Link>
)}
{tagline && <Text>{tagline}</Text>}
{feature && <Link href={feature.href}>{feature.item.headline}</Link>}
</Section>
);
}

The HTML of the email, and the positions of the slots it rendered. A send records the items of those slots only. A template that renders some of the slots returns just theirs.

EdgeKit supports a contract until 12 months after the next contract ships. Contract 2 shipped on 2026-11-07, so contract 1’s support ends on 2027-11-07 UTC. Contract 2 has no successor yet, so it has no end date.

From 2027-02-07, 9 months before the end date, edgekit templates validate, edgekit templates push, edgekit deploy diff and Checks in the edition editor warn on each template version on contract 1 that they check:

The template bundle is on contract 1, whose support ends on 2027-11-07 UTC: rebuild it on the latest @edgekitcloud/email, then push and deploy it before then, or its sends fail.

Checks and deploy diff name the template, such as Template "custom:digest", in place of The template bundle.

From the end date on:

  • A push of a template bundle on contract 1 is refused, even one whose bytes are already the draft’s.
  • Each send, preview and test send that renders a version on contract 1 fails before the template runs, with The edition could not render: Template "custom:digest" is on contract 1, whose support ended on 2027-11-07 UTC: …. Checks shows the same sentence as an error.

Checks reads the window at the edition’s send time, so an edition that sends after the end date shows the error already.

edgekit templates validate runs offline, so it reads the end dates in the CLI release you run: update the CLI to see an end date set after that release. --remote, a push, a deploy diff, Checks and a send read the end dates of the EdgeKit release that runs them.

Until its support ends, a template built on 1.x keeps rendering with contract 1’s input: contract 2’s without creative. It renders an ad slot’s tag or nothing, and never sees an ad slot a creative fills. So that no creative is booked where it cannot show, while any variant of a publication uses a custom template on contract 1:

  • a creative cannot be placed in that publication’s ad slots;
  • none of its ad slots can take an ad type or a default unsold fill.

A contract 1 template bundle that declares adTypes is refused at push. To move a template to contract 2, update @edgekitcloud/email to 2.x, handle creative on an ad slot, rebuild, then push and deploy it.

defineTemplate turns a React Email component into the template bundle’s default export:

import {
FirstName,
Unsubscribe,
catalogueFor,
defineTemplate,
} from '@edgekitcloud/email';
import {
Body,
Container,
Heading,
Html,
Img,
Link,
Section,
Text,
} from 'react-email';
import { z } from 'zod';
const messages = {
en: { hello: 'Hello', friend: 'friend', unsubscribe: 'Unsubscribe' },
};
export default defineTemplate({
name: 'digest',
locales: ['en'],
props: z.object({ heading: z.string().max(80).optional() }),
component: ({ edition, props, locale, brand }) => {
const t = catalogueFor(messages, locale)!;
return (
<Html lang={locale}>
<Body>
<Container>
<Heading>{props.heading ?? brand?.name ?? 'Today'}</Heading>
<Text>
{t.hello} <FirstName fallback={t.friend} />,
</Text>
{edition.slots.map((slot) => (
<Section key={slot.position}>
{slot.title && <Heading as="h2">{slot.title}</Heading>}
{slot.kind === 'rich_text' ? (
slot.content.map((block) =>
block._type === 'image' ? (
<Img
key={block._key}
src={block.url}
alt={block.alt}
width={560}
/>
) : (
<Text key={block._key}>
{block.children.map((span) => span.text).join('')}
</Text>
),
)
) : slot.kind === 'image' ? (
<Img src={slot.image.url} alt={slot.image.alt} width={560} />
) : 'items' in slot ? (
slot.items.map((item) => (
<Text key={item.link}>
<Link href={item.link}>{item.headline}</Link>
</Text>
))
) : null}
</Section>
))}
<Unsubscribe>
{(href) => (
<Text>
<Link href={href}>{t.unsubscribe}</Link>
</Text>
)}
</Unsubscribe>
</Container>
</Body>
</Html>
);
},
});

The options:

  • name: the template’s name. A variant names it custom:<name>.
  • locales: every locale you have copy for. A regional locale is served by its language’s copy, so en serves en-GB, but a language is never served by another one’s.
  • props: a validator for the variant’s props. Any Standard Schema validator works, such as a zod, Valibot or ArkType schema. Saving a variant runs it, and so does every render. A refusal is one sentence: Template "custom:digest" refused its props: heading — , then your validator’s message.
  • fixtureProps (optional): the props EdgeKit renders every fixture with when you push, as JSON of at most 16 KB. Without it each fixture gets {}, so set it when a prop is required. If your validator refuses them, the push is refused.
  • blocks (optional): the EdgeKit block keys your component lays out, such as rich-text and story-cards. A stack slot’s palette can offer only these blocks, and without blocks your template takes no stack slot. A push refuses more than 50 keys, and any key that is not one of EdgeKit’s blocks.
  • adTypes (optional): the ad types your component renders a creative of, by key, such as banner or your organization’s partner-spotlight. Without adTypes your template renders no creative, and a slot whose ad type it does not list cannot be booked while a variant uses it. A push refuses a key that is not a lowercase letter, then lowercase letters, digits and hyphens, and a key listed twice. Whether each key is an ad type your organization has is checked when you deploy.
  • component: the email. It gets the input above, with props as your validator returned them.
  • selectSlots (optional): the slots to render, when not all. component then gets only those.

React Email’s render runs once per send, without prettifying. Tailwind is up to you: wrap your email in React Email’s <Tailwind> if you use it.

Your template never sees a recipient. It writes placeholders, and EdgeKit fills them in after the render.

  • <FirstName fallback="friend" />: the recipient’s first name, or the fallback when their profile has none. The fallback cannot hold a brace or a %, or both kinds of quote mark. On the web archive, which has no recipient, it is the fallback.
  • <Unsubscribe>{(href) => …}</Unsubscribe>: EdgeKit’s unsubscribe link. Your function gets the recipient’s own URL for an href. Every email must render one: EdgeKit refuses a send whose HTML has none. On the web archive the whole region goes, so put anything that should go with the link, such as its paragraph, inside it.
  • <AdUnit slot={slot} unit={index}>{({ href, src }) => …}</AdUnit>: one ad unit of an ad slot your ad network’s tag fills. Your function gets the link and image URLs EdgeKit fills for the recipient, for an <a href> and an <img src>. The plain-text version leaves whatever it rendered out.
  • <AdPixels slot={slot} />: the slot’s tracking images, 1×1. Your ad network may want them near the top of the email.

Each writes EdgeKit tokens into the HTML. token writes one directly, but there is no reason to: EdgeKit refuses an unknown token, a token with the wrong arguments, an unsubscribe URL outside <Unsubscribe> and an ad URL outside its <AdUnit>.

catalogueFor(catalogues, locale) picks a locale’s copy by the same rule that serves locales, and servesLocale asks whether a list of locales serves one.

A custom template cannot render a personalised feed slot. A variant that pairs one with a custom template cannot be saved.

Limit Value
Template bundle size 5 MB
HTML size 1 MB, after EdgeKit fills in its placeholders
CPU time per render 2,000 ms
Time per render 10 seconds
Network None: every request your code makes fails
Node.js modules None: the build refuses a node: import

A template that throws, or goes over a limit, fails the render with a sentence naming why. In a send, that fails the variant’s send for that edition.

After your template returns, and before anything is sent:

  • Placeholders are filled in for each recipient: the first name, and an unsubscribe link signed for that recipient. EdgeKit adds the one-click unsubscribe headers itself.
  • No content runs as code. Every brace outside EdgeKit’s own placeholders is encoded, so neither your text nor an editor’s can open a per-recipient expression. A {{ or {% inside <style> is refused.
  • Links to your site are tagged with the publication’s link template. A custom template does not mark its slots, so a parameter using {slot} or {slot_key} is left off its links.
  • The plain-text body is made from your HTML, as for the library’s templates.
  • On the web archive, a template’s HTML runs no script and submits no form. A push, and templates validate, refuse a template that renders a <script> element.

EdgeKit checks that the unsubscribe link is there, not that it is visible. Keeping it readable is yours.

@edgekitcloud/email/fixtures holds the editions EdgeKit renders a template against before it accepts a push, in both email and web form:

  • slotKinds: one slot of each kind, no brand and no send time.
  • emptySlots: a slot of each kind with no content, no items and no title. Your template must render these too.
  • maximal: every block key on every slot kind it takes, every rich-text style and mark, long text, text with quotes, angle brackets and braces, a send time, and every brand field.
  • maximalUnbranded: maximal with no brand.
  • creatives: one ad slot filled by a creative of each of EdgeKit’s ad types, and one of an organization’s own, partner-spotlight, which has a field of each type. A push renders only the slots whose ad types your template lists in adTypes, and skips the fixture when it lists none of them.

Each is plain JSON in contract 2’s input shape, without props.

When your template declares blocks, a push, edgekit templates validate and edgekit templates dev also render another fixture, stack, which @edgekitcloud/email/fixtures does not export. Its edition is maximal’s, with one child slot for each block you declare, in the order you declare them. Each child is maximal’s slot of that block, on the first slot kind the block accepts, numbered from 0 and with stack: 'stack'.

Render the fixtures in your own tests:

import { fixtures } from '@edgekitcloud/email/fixtures';
import template from './digest';
const { html, slots } = await template.render({
...fixtures.maximal,
props: { heading: 'Morning' },
});

Every type and function is in the @edgekitcloud/email reference, the fixtures under fixtures.

edgekit.ai