Documentation
Presentation Layer

Template Engine

Kitwork's layout engine compiles structured HTML templates directly into high-velocity responses with zero run-time allocations.

01

Template Syntax

Render dynamic variables and evaluate expressions safely inside your HTML using double curly braces {{ value }}.

welcome.kitwork.html
<div class="welcome-box">
    <h1>Welcome back, {{ user.name }}!</h1>
    <p>Your current role is: {{ user.role ?? "Guest" }}</p>
</div>
02

Layouts & Partials

Separate structural headers, sidebars, and footers into reusable components using Layout binds.

layout.kitwork.html
<html>
    {{ _head_ }}
    <body>
        {{ _navbar_ }}
        <main>
            {{ _page_ }}
        </main>
        {{ _footer_ }}
    </body>
</html>
03

High Performance Caching

Kitwork's rendering pipeline caches structured token hierarchies in memory to bypass redundant string generation.

cache.js
// Enable HTTP Cache at the router level
router.get("/home").cache("5s").handle((req, res) => {
    return res.html(home.page("welcome"));
});
04

Data Bindings & Expressions

Bind data contexts using the .bind(...) method. Write inline logical evaluations and nullish fallback checks inside templates.

bind-expression.js
// 1. JS Route Binding
const view = page.bind({
    user: { name: "Grace", active: true }
});

// 2. HTML Expression Evaluation
<div class="status-badge bg-red-500">
    Hello, Guest
</div>
05

Directory Layouts

Define the root view folder, attach layouts, link default footer/header partials, and assign notfound handlers.

layouts.js
const site = render.directory("views");

const home = site
    .path("/")
    .global(globalObj)
    .layout({
        navbar: "_navbar_",
        footer: "_footer_",
        head: "_head_"
    })
    .notfound("notfound");
06

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.

escaping.html
<!-- Escaped output: &lt;script&gt;alert(1)&lt;/script&gt; -->
<div>&#123;&#123; user.description &#125;&#125;</div>

<!-- Unescaped safe layout bindings are loaded cleanly: -->
<div>&#123;&#123; _page_ &#125;&#125;</div>