define
定义一个模板。
用法
与 block 语句配合使用:
{{ block "main" . }}
{{ print "default value if 'main' template is empty" }}
{{ end }}
{{ define "main" }}
<h1>{{ .Title }}</h1>
{{ .Content }}
{{ end }}与 partial 函数配合使用:
{{ partial "inline/foo.html" (dict "answer" 42) }}
{{ define "_partials/inline/foo.html" }}
{{ printf "The answer is %v." .answer }}
{{ end }}与 template 语句配合使用:
{{ template "foo" (dict "answer" 42) }}
{{ define "foo" }}
{{ printf "The answer is %v." .answer }}
{{ end }}更多信息参见 Go 的 text/template 文档。