# Template functions Template functions are callable from any template as `{{name args…}}`. They come from FuncMaps fixed when the instance is built. They do not see the current request; request-scoped behavior belongs on the [dot context](dot-context.md) via dot fields. Add FuncMaps with `Config.FuncMaps` or `xtemplate.WithFuncMaps(...)`. Three sets are present by default: xtemplate, Sprig, and Go’s built-ins (stdlib). ## xtemplate functions | Name | Summary | |---|---| | `markdown` | Render CommonMark/GFM (Goldmark) to HTML; optional front matter → `.Meta` / `.Body` | | `sanitizeHtml` | Sanitize HTML with a named BlueMonday policy (`strict`, `ugc`, `externalugc`, …) | | `humanize` | Human-readable `size` (bytes) or `time` (relative) strings | | `try` | Call a fallible func/method and get a result object instead of aborting | | `return` | Early-return successfully from the template | | `failf` | Fail execution with a formatted error (not an early return) | | `trustHtml` / `trustAttr` / `trustJS` / `trustJSStr` / `trustSrcSet` | Mark a string as trusted for a given context (escapes disabled) | | `idx` | Index into a slice/array/string with index first (pipeline-friendly) | Godoc entry points (same package): [`FuncMarkdown`](https://pkg.go.dev/github.com/infogulch/xtemplate#FuncMarkdown), [`FuncSanitizeHtml`](https://pkg.go.dev/github.com/infogulch/xtemplate#FuncSanitizeHtml), [`FuncHumanize`](https://pkg.go.dev/github.com/infogulch/xtemplate#FuncHumanize), [`FuncTry`](https://pkg.go.dev/github.com/infogulch/xtemplate#FuncTry), and siblings named `Func…`. ### Examples ```html {{/* Markdown with optional front matter */}} {{with markdown (.FS.Read "posts/hello.md")}}