templates - {{template "base"}} 和 {{template "base".}} 在 go-gin 中的区别

标签 templates go go-gin

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

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

最佳答案

来自 godoc text/template :

{{template "name"}}
The template with the specified name is executed with nil data.

{{template "name" pipeline}}
The template with the specified name is executed with dot set to the value of the pipeline.

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

关于templates - {{template "base"}} 和 {{template "base".}} 在 go-gin 中的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47686178/

相关文章:

javascript - 渲染模板的部分内容

docker - 获取docker内部Go所有依赖包

go - 如何同时使用 LoadHTMLGlob 和 LoadHTMLFiles

python - Jinja2 "recursive"标签实际上是如何工作的?

c++ - 可变参数模板类型推导

c++ - 模板和类型转换

google-app-engine - 如何使用 stdout Go 1.11 记录由跟踪 ID 关联的 Stackdriver 日志消息

http - 在golang fasthttp中获取任意请求 header value

Golang 模板不会加载

go - Gin /golang - 空请求体