eta template render: working versions (tested 2026-10-16)
Render eta v3 templates from an ephemeral temp views directory with layouts, partial includes and auto-escaping, plus renderString, fully offline.
passed3 passed · 0 failed2026-10-16 20:33 UTC- Status
- passed
- Last passed
- 2026-10-16 20:33 UTC
- Tests
- 3 / 3
- Language
- TypeScript
- Runtime
- node v22.23.3
pinned versions3
eta@4.6.0@types/node@26.6.5tsx@4.23.15
run it
npm install --no-audit --no-fund --ignore-scripts=false npm test
test environment
node v22.23.3 linux 6.17.0-1022-azure x64 runner: github-actions 38962988948
The code
Exactly the files that passed. Your agent can pull them with get_recipe("eta-template-render") (install), or see them on GitHub.
package.json
{
"name": "eta-template-render",
"private": true,
"type": "module",
"scripts": {
"test": "node --import tsx --test test/*.test.ts"
},
"dependencies": {
"eta": "4.6.0"
},
"devDependencies": {
"@types/node": "26.6.5",
"tsx": "4.23.15"
}
}
src/render.ts
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { Eta } from "eta";
export type LayoutData = {
title: string;
body: string;
};
const LAYOUT = [
"<!doctype html>",
"<html>",
"<head><title><%= it.title %></title></head>",
"<body>",
'<%~ include("./header.eta", { title: it.title }) %>',
"<main><%~ it.body %></main>",
"</body>",
"</html>",
].join("\n");
const HEADER = "<header><h1><%= it.title %></h1></header>";
export function createViewsDir(): string {
const dir = mkdtempSync(join(tmpdir(), "eta-views-"));
writeFileSync(join(dir, "layout.eta"), LAYOUT, "utf8");
writeFileSync(join(dir, "header.eta"), HEADER, "utf8");
return dir;
}
export function createEta(views: string): Eta {
return new Eta({ views, autoEscape: true, varName: "it", cache: false });
}
export function renderLayout(eta: Eta, data: LayoutData): string {
return eta.render("layout.eta", data);
}
export function renderInline(eta: Eta, template: string, data: Record<string, unknown>): string {
return eta.renderString(template, data);
}
export function cleanupViews(dir: string): void {
rmSync(dir, { recursive: true, force: true });
}
test/render.test.ts
import { after, test } from "node:test";
import assert from "node:assert/strict";
import {
cleanupViews,
createEta,
createViewsDir,
renderInline,
renderLayout,
} from "../src/render.ts";
const views = createViewsDir();
const eta = createEta(views);
after(() => {
cleanupViews(views);
});
test("renders a layout with a partial include", () => {
const html = renderLayout(eta, { title: "Home", body: "<p>Welcome</p>" });
assert.match(html, /<title>Home<\/title>/);
assert.match(html, /<header><h1>Home<\/h1><\/header>/);
assert.match(html, /<main><p>Welcome<\/p><\/main>/);
});
test("auto-escapes interpolated values in layout and partial", () => {
const html = renderLayout(eta, { title: "Home <b> & co", body: "<p>ok</p>" });
assert.match(html, /Home <b/);
assert.match(html, /& co/);
assert.doesNotMatch(html, /<b>/);
});
test("renderString escapes data", () => {
const out = renderInline(eta, "<p><%= it.msg %></p>", { msg: "a & b < c" });
assert.equal(out, "<p>a & b < c</p>");
});
Connect to ProvenPin
Add the free MCP server so your agent can pull this recipe and others like it. Same setup as the docs.
terminal
claude mcp add --transport http provenpin https://mcp.provenpin.com/mcp
~/.cursor/mcp.json
{ "mcpServers": { "provenpin": { "url": "https://mcp.provenpin.com/mcp" } } }.vscode/mcp.json
{ "servers": { "provenpin": { "type": "http", "url": "https://mcp.provenpin.com/mcp" } } }~/.codeium/windsurf/mcp_config.json
{ "mcpServers": { "provenpin": { "serverUrl": "https://mcp.provenpin.com/mcp" } } }MCP settings
{ "mcpServers": { "provenpin": { "type": "streamableHttp", "url": "https://mcp.provenpin.com/mcp" } } }Any other MCP client: Streamable HTTP at https://mcp.provenpin.com/mcp. No API key, no signup.