I am new to Go language. I work on a Basic MVC Web Application in Go (josephspurrier's project on https://github.com/josephspurrier/gowebapp/blob/master/README.md). I have a controller which consumes a REST web service:
func InfoGET(w http.ResponseWriter, r *http.Request) {
var infos []model.Info
//call web service and get data
infos, err := ws.GetAllInfos("tho")
if(err != nil) {
log.Println(err)
}
v := view.New(r)
v.Name = "infos/info"
v.Render(w)
}
I want to display the data I have gotten thanks to the webservice (displaying them in a datatable would be great I think). What do I have to write in my .tmpl file in order to achieve this?
There's an example:
Controller: https://github.com/josephspurrier/gowebapp/blob/master/vendor/app/controller/notepad.go
View: https://github.com/josephspurrier/gowebapp/blob/master/template/notepad/read.tmpl
// This adds your collection to the template
v.Vars["infos"] = infos
In your template you iterate over your infos using range:
{{range $info := .infos}}
Inside range you access specific properties using {{.PropertyName}}