Skip to content

Template Functions

Functions available in all Go templates. Call with Go template syntax: {{functionName args}}

FunctionDescriptionExample
formatDateFormat time.Time{{formatDate .Post.Date "Jan 2, 2006"}}
readingTimeReading time string{{readingTime .Post}}
truncateTruncate with ellipsis{{truncate .Description 160}}
safeHTMLMark trusted HTML{{safeHTML .Post.HTML}}
slugifyConvert to URL slug{{slugify .Tag.Name}}
currentYearCurrent year int{{currentYear}}
hasPrefixString prefix check{{if hasPrefix .Nav.Path "/admin"}}
lowerLowercase{{lower .Tag.Name}}
upperUppercase{{upper .Post.Title}}
joinJoin string slice{{join .Post.Tags ", "}}
addAdd two ints{{add .Pagination.CurrentPage 1}}
subSubtract two ints{{sub .Pagination.TotalPages 1}}
seqGenerate int sequence{{range seq 1 5}}...{{end}}
jsonLDJSON-LD script tag{{jsonLD .Meta}}
cacheVerCache-bust version{{cacheVer}} (hourly)
i18nLocalized 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.

Released under the MIT License.