I am a golang beginner and I am developing a web application to understand better the golang concepts.
I have a html page which I want to show some informations about User and about a Product.
So, now I am passing only the Product struct to the Product html template, like this:
ExecuteTemplate(w, "product", Product)
But I have some informations that are not in this struct. That are in the User struct.
I would have to do something like this:
ExecuteTemplate(w, "product", Product, User)
I mean that I have to pass both structs to the same template. Is there a way to do this ?
Invoke the template as
if err := t.ExecuteTemplate(w, "product",
struct{Product, User interface{}}{Product, User}); err != nil {
// handle error
}
You can access product and user inside the template as:
{{.Product}}
{{.User}}