# Template
_Path: en/lua/text/template_
## Table of Contents
- Template Engine
## Content
# Template Engine
Render dynamic content using the [Jet template engine](https://github.com/CloudyKit/jet). Build HTML pages, emails, and documents with template inheritance and includes.
For template set configuration, see [Template Engine](system/template.md).
## Loading
```lua
local templates = require("templates")
```
## Acquiring Template Sets
Get a template set by registry ID to start rendering:
```lua
local set, err = templates.get("app.views:emails")
if err then
return nil, err
end
-- Use the set...
set:release()
```
| Parameter | Type | Description |
|-----------|------|-------------|
| `id` | string | Template set registry ID |
**Returns:** `Set, error`
## Rendering Templates
Render a template by name with data:
```lua
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
```
| Parameter | Type | Description |
|-----------|------|-------------|
| `name` | string | Template name within the set |
| `data` | table | Variables to pass to template (optional) |
**Returns:** `string, error`
## Set Methods
| Method | Returns | Description |
|--------|---------|-------------|
| `render(name, data?)` | `string, error` | Render template with data |
| `release()` | `boolean` | Release set back to pool |
## Jet Syntax Reference
Jet uses `{{ }}` for expressions and control structures, `{* *}` for comments.
### Variables
```html
{{ user.name }}
{{ user.email }}
{{ items[0].price }}
```
### Conditionals
```html
{{ if order.shipped }}
Shipped!
{{ else if order.processing }}
Processing...
{{ else }}
Received.
{{ end }}
```
### Loops
```html
{{ range items }}
{{ .name }} - ${{ .price }}
{{ end }}
{{ range i, item := items }}
{{ i }}. {{ item.name }}
{{ end }}
```
### Inheritance
```html
{* Parent: layout.jet *}
{{ yield title() }}
{{ yield body() }}
{* Child: page.jet *}
{{ extends "layout" }}
{{ block title() }}My Page{{ end }}
{{ block body() }}Content
{{ end }}
```
### Includes
```html
{{ include "partials/header" }}
Content
{{ include "partials/footer" }}
```
## Errors
| Condition | Kind | Retryable |
|-----------|------|-----------|
| Empty ID | `errors.INVALID` | no |
| Empty template name | `errors.INVALID` | no |
| Permission denied | `errors.PERMISSION_DENIED` | no |
| Template not found | `errors.NOT_FOUND` | no |
| Render error | `errors.INTERNAL` | no |
| Set already released | `errors.INTERNAL` | no |
See [Error Handling](lua/core/errors.md) for working with errors.
## Navigation
Previous: Text (lua/text/text)
Next: TreeSitter (lua/text/treesitter)