I have this code for html/template, and it won't run. I want to display each element in the array and it will return nothing. Please ignore the ioutil file reading.
type Person struct {
Name string
Age int
}
type Page struct {
test [3]Person
test2 string
}
func main() {
var a [3]Person
a[0] = Person{Name: "test", Age: 20}
a[1] = Person{Name: "test", Age: 20}
a[2] = Person{Name: "test", Age: 20}
p:= Page{test: a}
c, _ := ioutil.ReadFile("welcome.html")
s := string(c)
t := template.New("")
t, _ = t.Parse(s)
t.Execute(os.Stdout, p)
}
and welcome.html:
{{range .test}}
item
{{end}}