美文网首页
go template 学习

go template 学习

作者: 漯河龙 | 来源:发表于2017-08-06 10:22 被阅读0次

func(c *MainController)Get() {

c.TplName ="index.tpl"

c.Data["TrueCond"]=true

c.Data["FalseCound"]=false

typeustruct{

Namestring

Ageint

Sexstring

}

user:=&u{

"zhangsan",

1,

"nan",

}

c.Data["User"] = user

num:=[]int{1,2,3,4,5}

c.Data["Nums"]=num

c.Data["TplVar"]="hey guys"

c.Data["Html"]="

hey guys

"

c.Data["Pipe"]="

hey guys

"

}

{{if.TrueCond}}

true condition.

{{end}}

{{if .FalseCond}}

{{else}}

false condition.

{{end}}

{{with .User}}

{{.Name}};{{.Sex}}{{.Age}}

{{end}}

{{range .Nums}}

{{.}}

{{end}}

{{$tplVar := .TplVar}}

{{$tplVar}}

{{$html := .Html}}

{{$html}}

{{str2html .Html}}

{{.Pipe | htmlquote}}

{{template "test"}}

{{define "test"}}

this is a tpl test

{{end}}

相关文章