模板
语法
template NAME [CONTEXT]
使用 template
函数执行嵌入式模板。例如
{{ range (.Paginate .Pages).Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}
您还可以使用 template
函数执行已定义的模板
{{ template "foo" (dict "answer" 42) }}
{{ define "foo" }}
{{ printf "The answer is %v." .answer }}
{{ end }}
上面的示例可以使用内联局部模板重写
{{ partial "inline/foo.html" (dict "answer" 42) }}
{{ define "partials/inline/foo.html" }}
{{ printf "The answer is %v." .answer }}
{{ end }}
有关更多信息,请参阅 Go 的 text/template 文档。