{{.SiteTitle}}

Template helpers
in action

22 helpers registered
across 6 groups

String helpers
{{$first := first .Articles}}

capitalize capitalize

{{capitalize $first.Title}}

input: "{{$first.Title}}"

truncate truncate

{{$first.Excerpt | truncate 80}}

capped at 80 chars

prepend prepend

{{prepend $first.Slug "/articles/"}}

prepended "/articles/" to slug

strAppend strAppend

{{strAppend $first.Slug ".html"}}

appended ".html" to slug

split → join split join

{{$parts := split "go,templates,funcmap" ","}}

{{join $parts " · "}}

split on "," then joined with " · "

Number & Date helpers

fmtNumber — int fmtNumber

{{fmtNumber $first.Views}}

raw value: {{$first.Views}}

{{$paid := index .Articles 2}}

fmtNumber — float fmtNumber

$ {{fmtNumber $paid.Price}}

raw value: {{$paid.Price}}

fmtDate "short" fmtDate

{{fmtDate $first.PublishedAt "short"}}

layout: "02 Jan 2006"

fmtDate "long" fmtDate

{{fmtDate $first.PublishedAt "long"}}

layout: "02 January 2006"

fmtDate "iso" fmtDate

{{fmtDate $first.PublishedAt "iso"}}

layout: "2006-01-02"

timeAgo timeAgo

{{range .Articles}}

{{timeAgo .PublishedAt}} — {{fmtDate .PublishedAt "short"}}

{{end}}
Collection helpers

first first

{{with first .Articles}}

{{capitalize .Title}}

first article in the list

{{end}}

last last

{{with last .Articles}}

{{capitalize .Title}}

last article in the list

{{end}}

sliceOf 0–2 sliceOf

{{range sliceOf .Articles 0 2}}

— {{capitalize .Title}}

{{end}}

only first 2 of {{len .Articles}} articles

contains — slice contains

{{if contains $first.Tags "go"}}

✓ has tag "go"

{{else}}

✗ missing tag "go"

{{end}}

tags: {{join $first.Tags ", "}}

contains — string contains

{{if contains $first.Excerpt "FuncMap"}}

✓ excerpt mentions "FuncMap"

{{else}}

✗ not found

{{end}}

substring search on .Excerpt

join join

{{join $first.Tags " / "}}

tags joined with " / "

Logic helpers
{{range .Articles}} {{end}}
Helper Article Input Output
defaultVal {{.Title | capitalize | truncate 30}} .Subtitle ({{if .Subtitle}}"{{.Subtitle}}"{{else}}empty{{end}}) {{defaultVal "No subtitle" .Subtitle}}
ternary {{capitalize .Title | truncate 30}} .Featured = {{.Featured}} {{ternary "⭐ featured" "regular" .Featured}}
coalesce {{capitalize .Title | truncate 30}} .Subtitle → .Title {{coalesce .Subtitle .Title}}
Full article cards — all helpers combined
{{range .Articles}}
{{if .Featured}}featured{{end}} {{range .Tags}}{{.}}{{end}}

{{capitalize .Title}}

{{with coalesce .Subtitle ""}}

{{.}}

{{end}}

{{.Excerpt | truncate 160}}

{{prepend .Slug "/articles/"}} →
{{.Author.Avatar}}
{{capitalize .Author.Name}}
{{fmtNumber .Views}} views
{{if gt .Price 0.0}} $ {{fmtNumber .Price}} {{else}} free {{end}}
{{end}}