I got following struct:
type Data struct {
Data1 int
Data2 int
ImpData []struct {
Title string
ID string
TextS string
}
}
I unmarshall the jsoncode into var o
var o Data
err = json.Unmarshal(output, &o)
if err != nil {
panic(err.Error())
}
I get the data with a for loop
for i := 0; i < len(o.ImpData); i++ {
fmt.Printf(" Test: %+v", o.ImpData[i].Title)
}
Till this point everything works, but i dont know how to excatly execute the Template with the right parameters and data.
tmpl, _ := template.ParseFiles("index.html")
tmpl.Execute(w, ?)
HTML:
<p style="color: black;"> {{ range .ImpData }} {{ . }}</p>
I dont know how i get the Data in the HtMl Template, for exmaple if len(o.ImpData) is 5, I meed the Data 5 Times in the html template.
New contributor
Zentaurux is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.