[go]template使用

//index.html

{{if gt .Age 18}}
    <p>hello, old man, {{.Name}}</p>
{{else}}
    <p>hello,young man, {{.Name}}</p>
{{end}}
import (
	"text/template"
)

p := Person{Name: "Mary", Age: 11}

t, _ := template.ParseFiles("./index.html")
p := Person{Name: "Mary", Age: 11}
t.Execute(os.Stdout, p)
posted @ 2019-12-22 22:38  mmaotai  阅读(177)  评论(0编辑  收藏  举报