define
與 block
語句一起使用:
{{ block "main" . }}
{{ print "如果 'main' 範本為空,顯示預設值" }}
{{ end }}
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ end }}
與 partial
函數一起使用:
{{ partial "inline/foo.html" (dict "answer" 42) }}
{{ define "partials/inline/foo.html" }}
{{ printf "答案是 %v。" .answer }}
{{ end }}
與 template
函數一起使用:
{{ template "foo" (dict "answer" 42) }}
{{ define "foo" }}
{{ printf "答案是 %v。" .answer }}
{{ end }}
查看 Go 的 text/template 文件以獲得更多資訊。