A *template.Template is actually a group of named templates.
This line
> tmpl, err := template.New("").ParseFiles("templ.txt")
creates a *template.Template (tmpl) with two named templates: "" and
"templ.txt". The latter ("templ.txt") contains your actual template
data, while the former ("") is empty.
When you call tmpl.Execute, it tries to execute the first template,
"", which has no content. Hence the error.
You can fix this in one of two ways:
1. Call tmpl.ExecuteTemplate and name "templ.txt" explicitly:
> if err = tmpl.ExecuteTemplate(buf, "templ.txt", i); err != nil {
> log.Fatal(err)
> }
2. Use the package-level function template.ParseFiles to parse your template:
> tmpl, err := template.ParseFiles("templ.txt")
This returns a *template.Template with just one template, "templ.txt",
and so a call to tmpl.Execute will render just that template.
Andrew