npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@templatical/renderer

v0.64.1

Published

Render Templatical email templates to MJML

Readme

@templatical/renderer

JSON → MJML renderer for Templatical email templates. Runs in the browser or on Node.

npm version License

Converts Templatical's JSON template format into MJML, which you then compile to HTML using any MJML library. Pure functions, zero runtime dependencies aside from @templatical/types.

Use this on your backend to render templates server-side before sending email — or in the browser to preview before save.

Install

npm install @templatical/renderer mjml

Usage

Browser or Node — JSON → MJML

import { renderToMjml } from '@templatical/renderer';
import type { TemplateContent } from '@templatical/types';

const content: TemplateContent = JSON.parse(stored);
const mjml = await renderToMjml(content);

renderToMjml is async — it returns Promise<string>. Custom blocks may need async work to resolve, so the call always returns a promise even when content has none.

Node — MJML → HTML for sending

import { renderToMjml } from '@templatical/renderer';
import mjml2html from 'mjml';

const mjml = await renderToMjml(content);
const { html } = mjml2html(mjml);

// Send via Postmark, Resend, SES, Mailgun, anything
await mailer.send({ to, subject, html });

With custom fonts

const mjml = await renderToMjml(content, {
  customFonts: [
    { name: 'Geist', url: 'https://fonts.googleapis.com/...' },
  ],
  defaultFallbackFont: 'Arial, sans-serif',
  allowHtmlBlocks: true,
});

With custom blocks

Editor consumers use editor.toMjml(). Headless callers pass the registered definitions as customBlocks and the liquidjs module as liquidjs. Install liquidjs (^10.30.1) in the server project:

import * as liquidjs from 'liquidjs';
import { renderToMjml } from '@templatical/renderer';
import type { CustomBlockDefinition, TemplateContent } from '@templatical/types';

export async function renderTemplate(content: TemplateContent, definitions: CustomBlockDefinition[]) {
  return renderToMjml(content, { customBlocks: definitions, liquidjs });
}

The Custom blocks guide covers the option's fallback, conflicts and missing-module error. For a lower-level resolver, use createCustomBlockLiquid(liquidjs) from @templatical/types. Use {{ body | raw }} for a field intended to hold HTML. Always quote attribute values and validate URL schemes from untrusted sources. The editor canvas also sanitizes each rendered block; email output keeps the template's HTML.

Without a matching definition or callback, the renderer falls back to renderedHtml (if any) and otherwise omits the block.

API

  • renderToMjml(content, options?): Promise<string> — render TemplateContent to an MJML string. Pair with the mjml package to compile to final HTML.

Options:

  • customFonts — CustomFont[] declarations rendered into <mj-attributes>
  • defaultFallbackFont — fallback when a block doesn't specify a font
  • allowHtmlBlocks — pass false to strip HTML blocks before render (e.g. for untrusted content)
  • customBlocks — CustomBlockDefinition[] — render saved blocks from definitions
  • liquidjs — the liquidjs module (import * as liquidjs from "liquidjs"); required with customBlocks when the content holds a custom block
  • renderCustomBlock — (block: CustomBlock) => Promise<string> — resolves custom blocks to HTML

Documentation

Full reference at docs.templatical.com.

License

MIT