在text/template
包中的{{range pipeline}} T1 {{end}}
个操作内,是否有可能在Range操作之前访问管道值,或者将父/全局管道作为参数传递以执行?
展示我try 做什么的工作示例:
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"}})
}