【问题标题】:what does {{template "name" pipeline}} mean [duplicate]{{模板“名称”管道}}是什么意思[重复]
【发布时间】:2018-08-30 04:42:01
【问题描述】:

https://golang.org/pkg/text/template/#hdr-Actions中有如下解释

{{template "name" pipeline}} 指定名称的模板是 执行时将 dot 设置为管道的值。

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

比如我看到下面的模板代码-

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

...

{{ end }}

什么是'.'是否遵循上面代码中的“顶部”?

【问题讨论】:

标签: go go-templates


【解决方案1】:

值“。”是third paragraph in the documentation 中解释的当前值或光标:

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

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

【讨论】:

    猜你喜欢
    • 2010-09-29
    • 2021-04-26
    • 2013-10-09
    • 1970-01-01
    • 2018-01-12
    • 1970-01-01
    • 2010-11-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多