Template Functions
Functions available in all Go templates. Call with Go template syntax: {{functionName args}}
| Function | Description | Example |
|---|---|---|
formatDate | Format time.Time | {{formatDate .Post.Date "Jan 2, 2006"}} |
readingTime | Reading time string | {{readingTime .Post}} |
truncate | Truncate with ellipsis | {{truncate .Description 160}} |
safeHTML | Mark trusted HTML | {{safeHTML .Post.HTML}} |
slugify | Convert to URL slug | {{slugify .Tag.Name}} |
currentYear | Current year int | {{currentYear}} |
hasPrefix | String prefix check | {{if hasPrefix .Nav.Path "/admin"}} |
lower | Lowercase | {{lower .Tag.Name}} |
upper | Uppercase | {{upper .Post.Title}} |
join | Join string slice | {{join .Post.Tags ", "}} |
add | Add two ints | {{add .Pagination.CurrentPage 1}} |
sub | Subtract two ints | {{sub .Pagination.TotalPages 1}} |
seq | Generate int sequence | {{range seq 1 5}}...{{end}} |
jsonLD | JSON-LD script tag | {{jsonLD .Meta}} |
cacheVer | Cache-bust version | {{cacheVer}} (hourly) |
i18n | Localized string | {{i18n "subscribe"}} |
Usage Notes
WARNING
Only use safeHTML on content you trust (admin-authored posts/pages). Never use it on user-submitted content like comments or webmentions.
i18n Keys
Available translation keys: home, archive, tags, search, read_more, min_read, published_on, comments, post_comment, subscribe, unsubscribe, like, dislike, share, related_posts, draft, featured, powered_by, and more.