I have the following code:
package main
import (
"net/http"
"html/template"
)
type data struct {
Data string
}
func handler(w http.ResponseWriter, req *http.Request) {
t := template.New("Test")
t, _ = t.Parse("<html><body>Hello {{.Data}}</body></html>")
val := data {Data:"<input type=text>"}
t.Execute(w, val)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":1234", nil)
}
If I execute this code, the webpage displays: Hello <input type=text>
instead of Hello and a button.
What is the way to make HTML render from the go template output ?
Thanks
--
Sankar P
http://psankar.blogspot.com
package main
import (
"net/http"
"html/template"
)
type data struct {
Data string
}
func handler(w http.ResponseWriter, req *http.Request) {
t := template.New("Test")
t, _ = t.Parse("<html><body>Hello {{.Data}}</body></html>")
val := data {Data:"<input type=text>"}
t.Execute(w, val)
}
func main() {
http.HandleFunc("/", handler)
http.ListenAndServe(":1234", nil)
}
If I execute this code, the webpage displays: Hello <input type=text>
instead of Hello and a button.
What is the way to make HTML render from the go template output ?
Thank you a tonne :)
The templates thing is so under-documented, and most of the online
blog posts are out-dated. Your email helped me fix the problem that I
am stuck on. It works perfect now. Thanks a lot.