2 つのテキスト ファイル (go テンプレート) があるとします。
child.tmpl
TEXT1
Hello {{ . }}
top.tmpl
TEXT2
{{ template "child.tmpl" "argument"}}
child.tmpl
テンプレートはネストされていますtop.tmpl
それらを解析する典型的なプログラムは次のようになります:
package main
import (
"os"
"text/template"
)
func main() {
t := template.Must(template.ParseFiles("child.tmpl", "top.tmpl")
t.ExecuteTemplate(os.Stdout, "top.tmpl", nil)
}
{{ . }}
表記法を使用して、最上位のテンプレートに埋め込むテンプレートを引数として渡す方法はありますか? 何かのようなもの{{ template {{.}} "argument" }}
- より一般的には、複数の子テンプレートのトップレベル テンプレートのように使用できるように、レイアウト テンプレートを定義する最良の方法は何ですか?