是否有可能{{range pipeline}} T1 {{end}}在text/template包中的操作中访问范围操作之前的管道值,或者作为参数传递给 Execute 的父/全局管道?
显示我尝试做的工作的示例:
package main
import (
"os"
"text/template"
)
// .Path won't be accessible, because dot will be changed to the Files element
const page = `{{range .Files}}<script src="{{html .Path}}/js/{{html .}}"></script>{{end}}`
type scriptFiles struct {
Path string
Files []string
}
func main() {
t := template.New("page")
t = template.Must(t.Parse(page))
t.Execute(os.Stdout, &scriptFiles{"/var/www", []string{"go.js", "lang.js"}})
}
https://play.golang.org/p/gO6w0o3FeP
慕村225694
相关分类