如何在新行上打印“apple”、“orange”和“pear”?
去:
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)
}
电流输出:
<html>
<h1>Hello</h1>
<h1>appleorangepear</h1>
</html>
Go Playground 上的代码:http : //play.golang.org/p/yhyfcq--MM
相关分类