How do I print "apple", "orange", and "pear" on a new line?
GO:
const titlepage = `
<html>
<h1>{{ .Title}}</h1>
<h1>{{ range $i := .Body}}{{$i}}{{end}}</h1>
</html>
`
type tp struct {
Title string
Body []string
}
func Read() ([]string) {
a := []string{"apple", "orange", "pear"}
return a
}
func main() {
as := tp{Title: "Hello", Body: Read()}
t := template.Must(template.New("Tele").Parse(titlepage))
t.Execute(os.Stdout, as)
}
Current output:
<html>
<h1>Hello</h1>
<h1>appleorangepear</h1>
</html>
The code on Go Playground: http://play.golang.org/p/yhyfcq--MM