在https://golang.org/pkg/text/template/#hdr-Actions , 有如下解释
{{template "name" pipeline}} The template with the specified name is
executed with dot set to the value of the pipeline.
这是什么意思?什么是点?
例如,我看到下面的模板代码——
{{ define "header" }}
{{ template "top" . }}
{{ template "needs" }}
...
{{ end }}
什么是“.”跟随上面代码中的“顶部”?
值“.”是当前值或光标,如 third paragraph in the documentation 中所述:
Annotations in the template refer to elements of the data structure (typically a field of a struct or a key in a map) to control execution and derive values to be displayed. Execution of the template walks the structure and sets the cursor, represented by a period '.' and called "dot", to the value at the current location in the structure as execution proceeds.
命令 {{ template "top". }}
以点作为参数执行模板“top”。在“top”内部,点被设置为参数。