ドキュメントを読んでもあまり役に立ちませんでした。構造が
{{header}}
{{content that always changes}}
{{footer}}
golangで実現可能です。
それを標準出力にレンダリングするコード
t := template.Must(template.ParseFiles("main.tmpl", "head.tmpl", "foot.tmpl"))
t.Execute(os.Stdout, nil)
main.tmpl:
{{template "header" .}}
<p>main content</p>
{{template "footer" .}}
足.tmpl:
{{define "footer"}}
<footer>This is the foot</footer>
{{end}}
head.tmpl:
{{define "header"}}
<header>This is the head</header>
{{end}}
これにより、次のようになります。
<header>This is the head</header>
<p>main content</p>
<footer>This is the foot</footer>
html/templateの使用は非常に似ています。