Template Engine
Template Engine
Section titled “Template Engine”Template rendering using CloudyKit Jet.
Entry Kinds
Section titled “Entry Kinds”| Kind | Description |
|---|---|
template.set | Template set with shared configuration |
template.jet | Individual template |
Template Sets
Section titled “Template Sets”A set is a namespace containing related templates. Templates within a set share configuration and can reference each other by name.
- name: views kind: template.setAll configuration is optional with sensible defaults:
| Field | Type | Default | Description |
|---|---|---|---|
engine.development_mode | bool | false | Disable template caching |
engine.delimiters.left | string | {{ | Variable opening delimiter |
engine.delimiters.right | string | }} | Variable closing delimiter |
engine.delimiters.comment_left | string | {* | Comment opening delimiter |
engine.delimiters.comment_right | string | *} | Comment closing delimiter |
engine.extensions | string[] | [.jet, .html.jet, .jet.html] | Template file extensions |
engine.globals | map | - | Variables available to all templates |
Templates
Section titled “Templates”Templates belong to a set and are identified by name for internal resolution.
- name: layout kind: template.jet set: app.views:views source: | <html> <body>{{ yield content() }}</body> </html>
- name: home kind: template.jet set: app.views:views source: | {{ extends "layout" }} {{ block content() }} <h1>Welcome, {{ name }}</h1> {{ end }}| Field | Type | Required | Description |
|---|---|---|---|
set | reference | Yes | Parent template set |
source | string | Yes | Template content |
Template Resolution
Section titled “Template Resolution”Templates reference each other using names, not registry IDs. The resolution works like a virtual filesystem within the set:
- By default, the registry entry name (
entry.ID.Name) becomes the template name - Override with
meta.namefor custom naming:
- name: email-welcome-v2 kind: template.jet set: app.emails:templates meta: name: welcome source: | {{ include "header" }} Hello {{ user }}!This template is registered as welcome in the set, so other templates use {{ include "welcome" }} or {{ extends "welcome" }}.
Inheritance
Section titled “Inheritance”Templates can extend parent templates and override blocks:
# Parent defines yield points- name: base kind: template.jet set: app.views:views source: | <html> <head><title>{{ yield title() }}</title></head> <body>{{ yield body() }}</body> </html>
# Child extends and fills blocks- name: page kind: template.jet set: app.views:views source: | {{ extends "base" }} {{ block title() }}My Page{{ end }} {{ block body() }}<p>Content here</p>{{ end }}Lua API
Section titled “Lua API”See Template Module for rendering operations.
See Also
Section titled “See Also”- Template Module - Lua API reference
- Filesystem - Loading templates from disk
- HTTP Endpoint - Rendering templates from request handlers