The initial value of your pipeline (dot) is the value you pass to Template.Execute() , which in your case is Files which is of type []File .
Thus, at run time, the dot . equal to []File . This slice does not have a field or method named Files , which means .Files in your template.
What you have to do, just use . which refers to your fragment:
const tmpl = ` {{range .}} file {{.}} {{end}} `
And it's all. Testing:
var Files []File = []File{ File{"data.txt", 123}, File{"prog.txt", 5678}, } t := template.Must(template.New("html").Parse(tmpl)) err := t.Execute(os.Stdout, Files)
Conclusion (try on the Go Playground ):
file {data.txt 123} file {prog.txt 5678}
source share