Suppose that I have tow text files (go templates):
child.tmpl
TEXT1
Hello {{ . }}
top.tmpl
TEXT2
{{ template "child.tmpl" "argument"}}
the child.tmpl
template is nested in top.tmpl
A typical program to parse them will be :
package main
import (
"os"
"text/template"
)
func main() {
t := template.Must(template.ParseFiles("child.tmpl", "top.tmpl")
t.ExecuteTemplate(os.Stdout, "top.tmpl", nil)
}
Is there any method the pass the template to be embedded in the top-level template as an argument using the {{ . }}
notation ?
something like {{ template {{.}} "argument" }}
- More generally, what is the best way to define a layout template so I can use it like a top-level template to multiple child templates ?