This module provides templating utilities for rendering dynamic HTML content.
| Feature | Description | Use Case |
|---|---|---|
| TSX | Tags in .tsx files that are real DOM elements |
Markup written in TypeScript, built once and updated by assignment |
| html | Tagged template literal with update support | Single-use templates with in-place updates |
| compileTemplate | Full-featured template compiler | Reusable templates with loops, conditionals, pipes, event handling |
| Pipes | Value transformation functions | Format dates, currencies, text in templates |
| check | Static check of compileTemplate expressions against <T, F> |
Catch a misspelled path or handler in CI instead of in the browser |
| TableRenderer | Table row renderer for Web Components | Data tables with row updates and button handlers |
Best for: One template with values spliced in from JavaScript
const card = html`<div>{{name}}</div>`;
const result = card({ name: 'John' });
container.appendChild(result.fragment);
result.update({ name: 'Jane' }); // Updates in placeBest for: Complex templates with loops and conditionals
const { content, render } = compileTemplate(`
<ul>
<li loop="item in items" if="item.visible">{{item.name}}</li>
</ul>
`);
render({ items: [...] });Best for: Data tables in Web Components
const renderer = new TableRenderer(table, template, 'id', this);
renderer.render(data);
renderer.updateRow(id, newData);Start with where the markup lives.
- Markup arrives as text (an HTML file, a
<template>element, a server response, a CMS)? UsecompileTemplate. Text cannot be TSX, andcompileTemplategives text loops, conditionals, pipes and events. - Markup is written in TypeScript next to the code that uses it? Use TSX. Loops and conditions are plain TypeScript, every tag and prop is type-checked, and the result is the element itself.
- No JSX settings in the build, or values re-bound in place many times?
htmlneeds no compiler settings and updates its{{}}slots in place.
Both html and compileTemplate update in place, and each call site owns one DOM tree. TSX
builds once; you update the elements you kept.
- Plain values, no loops or conditionals? → Use
html - Need loops/conditionals? → Use
compileTemplate - Need loops together with event handlers? → Use
compileTemplatewithr-<event>attributes - Building a data table? → Use
TableRenderer - Want template mistakes caught before the app runs? → Use
compileTemplate<T, F>andnpx @relax.js/core check