lite-template
lite-template
lite-template ist eine minimalistische asynchrone Template-Engine für Microservices, statische Website-Generatoren und Dokumenten-Renderer. Sie bietet Kompatibilität mit EJS-Tags ohne den Ballast schwerer Engines.
Asynchrone Auswertung
lite-template kompiliert Templates in asynchrone JavaScript-Funktionen, sodass Sie Datenbankabfragen oder asynchrone Hilfsfunktionen direkt in Template-Tags mit await ausführen können.
Installation
pnpm
npm
bun
pnpm add lite-template
npm install lite-template
bun add lite-template
Verwendung
import { render } from 'lite-template';
const template = `
<header>
<h1><%= title %></h1>
<p><%- description %></p>
<ul>
<% for (const item of items) { %>
<li><%= item %></li>
<% } %>
</ul>
</header>
`;
const output = await render(template, {
title: "Willkommen bei docmd",
description: "Dokumentations-Engine <strong>v0.10.0</strong>",
items: ["Schnell", "Zero-Config", "Erweiterbar"]
});
console.log(output);
Tag-Syntax
| Tag | Zweck | Beispiel |
|---|---|---|
<%= value %> |
HTML-maskierte Ausgabe | <%= user.name %> |
<%- value %> |
Unmaskierte Rohausgabe | <%- rawHtml %> |
<% code %> |
Skript-Ausführung / Schleifen | <% if (active) { %> |
<%# comment %> |
Template-Kommentar | <%# interner Hinweis %> |