Template Engine
Kitwork's layout engine compiles structured HTML templates directly into high-velocity responses with zero run-time allocations.
Template Syntax
Render dynamic variables and evaluate expressions safely inside your HTML using double curly braces {{ value }}.
<h1>Welcome back, {{ user.name }}!</h1>
<p>Your current role is: {{ user.role ?? "Guest" }}</p>
</div>
Layouts & Partials
Separate structural headers, sidebars, and footers into reusable components using Layout binds.
{{ _head_ }}
<body>
{{ _navbar_ }}
<main>
{{ _page_ }}
</main>
{{ _footer_ }}
</body>
</html>
High Performance Caching
Kitwork's rendering pipeline caches structured token hierarchies in memory to bypass redundant string generation.
router.get("/home").cache("5s").handle((req, res) => {
return res.html(home.page("welcome"));
});
Data Bindings & Expressions
Bind data contexts using the .bind(...) method. Write inline logical evaluations and nullish fallback checks inside templates.
const view = page.bind({
user: { name: "Grace", active: true }
});
// 2. HTML Expression Evaluation
<div class="status-badge bg-red-500">
Hello, Guest
</div>
Directory Layouts
Define the root view folder, attach layouts, link default footer/header partials, and assign notfound handlers.
const home = site
.path("/")
.global(globalObj)
.layout({
navbar: "_navbar_",
footer: "_footer_",
head: "_head_"
})
.notfound("notfound");
XSS Escaping & Safe HTML Injection
By default, double curly braces {{ value }} escape all HTML symbols to defend against Cross-Site Scripting (XSS) injections. If you need to output unescaped raw HTML blocks, wrap layout symbols inside subview references.
<div>{{ user.description }}</div>
<!-- Unescaped safe layout bindings are loaded cleanly: -->
<div>{{ _page_ }}</div>