go template 学习

2017-08-06  本文已影响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}}

上一篇 下一篇

猜你喜欢

热点阅读