{{template“name”pipeline}}是什么意思[重复]

问题描述 投票:0回答:1

这个问题在这里已有答案:

https://golang.org/pkg/text/template/#hdr-Actions,它有以下解释

{{template“name”pipeline}}具有指定名称的模板在点设置为管道值的情况下执行。

这是什么意思?什么是点?

例如,我看到以下模板代码 -

{{ define "header" }}
{{ template "top" . }}
{{ template "needs" }}

...

{{ end }}

是什么 '。'跟随上面代码中的“顶部”?

go go-templates
1个回答
1
投票

价值 '。'是third paragraph in the documentation中解释的当前值或游标:

模板中的注释引用数据结构的元素(通常是结构的字段或映射中的键)来控制执行并派生要显示的值。执行模板遍历结构并设置光标,由句点'。'表示。并且在执行过程中将“dot”称为结构中当前位置的值。

命令{{ template "top" . }}以点为参数执行模板“top”。在“top”里面,dot被设置为参数。

© www.soinside.com 2019 - 2024. All rights reserved.