【问题标题】:Difference between {{template "base" }} and {{template "base" .}} in go-gingo-gin 中 {{template "base" }} 和 {{template "base" .}} 的区别
【发布时间】:2017-12-09 13:43:18
【问题描述】:

{{template "base" }}{{template "base" .}} 有什么区别?

我使用go-gin,两者都可以正常运行。我在文档中找不到关于此的任何描述。

【问题讨论】:

标签: templates go go-gin


【解决方案1】:

来自godoc text/template

{{template "name"}}
指定名称的模板以 nil 数据执行。

{{template "name" pipeline}}
指定名称的模板用点集执行 到管道的价值。

所以{{template "base"}} 调用模板base 时上下文中没有数据(当然,全局变量仍然可用),{{template "base" .}} 调用它时使用范围内的任何数据。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-23
    • 1970-01-01
    • 2015-11-07
    • 2013-01-20
    • 1970-01-01
    • 2020-12-27
    相关资源
    最近更新 更多