go - {{template "name"pipeline}} 是什么意思

标签 go go-templates

<分区>

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”内部,点被设置为参数。

关于go - {{template "name"pipeline}} 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52089331/

相关文章:

macos - OSX 10.10.2 - cmd 启动未定义显示

go - 在 Golang 中通过模板解析自定义变量

go - Go本地包中的未定义函数

go - 将一个字符串连接到一个结构片段

json - 使用 GoModifyTags 将 bson 标签添加到 go 结构

go - 模板和自定义函数;错误 : executing "templName" at <"funcName"> is not a define function

kubernetes - 使用go-template返回正确的键值

go - 范围内的转义模板

kubernetes - 如何在 Helm 子图中设置与环境相关的 values.yaml?

go - go-sqlcipher:无法在Windows上编译/运行示例