增加模板引擎内置变量使用示例

This commit is contained in:
john
2018-09-05 13:33:46 +08:00
parent 7d73e1080c
commit 2219d00f6c
3 changed files with 23 additions and 8 deletions

View File

@ -0,0 +1,18 @@
package main
import (
"gitee.com/johng/gf/g"
"gitee.com/johng/gf/g/net/ghttp"
)
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request){
r.Cookie.Set("theme", "default")
r.Session.Set("name", "john")
content :=`Config:{{.Config.redis.cache}}, Cookie:{{.Cookie.theme}}, Session:{{.Session.name}}`
r.Response.WriteTplContent(content, nil)
})
s.SetPort(8199)
s.Run()
}

View File

@ -0,0 +1,4 @@
# Redis数据库配置
[redis]
disk = "127.0.0.1:6379,0"
cache = "127.0.0.1:6379,1"

View File

@ -8,14 +8,7 @@ import (
func main() {
s := g.Server()
s.BindHandler("/", func(r *ghttp.Request){
content :=
`
{{if (get "name")}}
{{get "name"}}
{{else}}
NoName
{{end}}
`
content :=`{{if (get "name")}} {{get "name"}} {{else}} NoName {{end}}`
r.Response.WriteTplContent(content, nil)
})
s.SetPort(8199)