0

What is the difference between {{template "base" }} and {{template "base" .}}?

I use go-gin, both can run with no problem. I cannot find any description in the documentation about this.

faintsignal
  • 1,828
  • 3
  • 22
  • 30
seokgyu
  • 147
  • 1
  • 11
  • 2
    For explanation of the concept and answer to your question, see [golang template engine pipelines](https://stackoverflow.com/questions/42507958/golang-template-engine-pipelines/42508255#42508255). – icza Dec 07 '17 at 09:40

1 Answers1

1

From 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.

So {{template "base"}} calls the template base with no data in the context (globals are still available, of course), and {{template "base" .}} calls it with whatever data is in-scope at the point of the call.

hobbs
  • 223,387
  • 19
  • 210
  • 288