我尝试在 text/html 模板包中获得一些优点。我已经从 golang 站点阅读了它的文档。很难理解 . (点)在一般情况下,在一定的时间范围内动作。“管道”究竟是什么意思,可能因为我的英语不是母语而难以理解):
{{pipeline}}
The default textual representation of the value of the pipeline
is copied to the output.
让我们考虑一个例子:
data := map[string]interface{}{
"struct": &Order{
ID: 1,
CustID: 2,
Total: 3.65,
Name: "Something",
},
"name1": "Timur",
"name2": "Renat",
}
t.ExecuteTemplate(rw, "index", data)
这是“索引”:
{{define "index"}}
{{range $x := .}}
{{.}}
<b>{{$x}}</b><br>
<i>{{$.struct.ID}}</i><br>
<br>
# the lines below don't work and break the loop
# {{.ID}}
# or
# {{.struct.ID}}
# what if I want here another range loop that handles "struct" members
# when I reach "struct" field in the data variable or just do nothing
# and just continue the loop?
{{end}}
{{end}}
输出:
帖木儿
帖木儿
1
长Renat
长Renat
1
{1 2 3.65 某事}
{1 2 3.65 某事}
1
相关分类