Skip to content

Template Engine

Render dynamic content using the Jet template engine. Build HTML pages, emails, and documents with template inheritance and includes.

For template set configuration, see Template Engine.

local templates = require("templates")

Get a template set by registry ID to start rendering:

local set, err = templates.get("app.views:emails")
if err then
return nil, err
end
-- Use the set...
set:release()
ParameterTypeDescription
idstringTemplate set registry ID

Returns: Set, error

Render a template by name with data:

local set = templates.get("app.views:emails")
local html, err = set:render("welcome", {
user = {name = "Alice", email = "alice@example.com"},
activation_url = "https://example.com/activate?token=abc"
})
if err then
set:release()
return nil, err
end
set:release()
return html
ParameterTypeDescription
namestringTemplate name within the set
datatableVariables to pass to template (optional)

Returns: string, error

MethodReturnsDescription
render(name, data?)string, errorRender template with data
release()booleanRelease set back to pool

Jet uses {{ }} for expressions and control structures, {* *} for comments.

{{ user.name }}
{{ user.email }}
{{ items[0].price }}
{{ if order.shipped }}
<p>Shipped!</p>
{{ else if order.processing }}
<p>Processing...</p>
{{ else }}
<p>Received.</p>
{{ end }}
{{ range items }}
<li>{{ .name }} - ${{ .price }}</li>
{{ end }}
{{ range i, item := items }}
<p>{{ i }}. {{ item.name }}</p>
{{ end }}
{* Parent: layout.jet *}
<html>
<head><title>{{ yield title() }}</title></head>
<body>{{ yield body() }}</body>
</html>
{* Child: page.jet *}
{{ extends "layout" }}
{{ block title() }}My Page{{ end }}
{{ block body() }}<p>Content</p>{{ end }}
{{ include "partials/header" }}
<main>Content</main>
{{ include "partials/footer" }}
ConditionKindRetryable
Empty IDerrors.INVALIDno
Empty template nameerrors.INVALIDno
Permission deniederrors.PERMISSION_DENIEDno
Template not founderrors.NOT_FOUNDno
Render errorerrors.INTERNALno
Set already releasederrors.INTERNALno

See Error Handling for working with errors.