Skip to main content
Lightning uses Go’s standard text/template package for server-side rendering. Load templates once at startup with app.LoadHTMLGlob(), then render them from any handler with ctx.HTML().

Loading Templates

Call app.LoadHTMLGlob(pattern) before starting the server. The pattern follows the same glob syntax as filepath.Glob.
LoadHTMLGlob panics if the pattern matches no files or if any template fails to parse. Always verify your template paths before deploying.

Custom Template Functions

Register custom functions with app.SetFuncMap() before calling app.LoadHTMLGlob(). The function map is applied when templates are parsed.

Rendering a Template

Call ctx.HTML(code, name, data) from a handler. name is the template file name as registered by the glob, and data is any value passed as the template’s dot (.).
If template execution fails, Lightning responds with 500 and the error message as plain text.

Complete Example

1

Create the template file

templates/index.tmpl:
2

Write the server code

main.go:
3

Run and visit the page

Use lightning.Map (a map[string]any alias) to pass ad-hoc template data without defining a dedicated struct.