[gogf/gf]gf版本1.11.6和1.11.7模版变量无法解析

2024-06-25 94 views
5

升级到1.11.6和1.11.7后 模版变量,内置函数,自定义函数等无法解析

复现方式: 升级到1.11.6或者1.11.7

func main() {
    //g.Server().Run()
    s := g.Server()
    s.BindHandler("/aaa", 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}}, Query:{{.Query.name}}`
        r.Response.WriteTplContent(content, nil)
    })
    s.SetPort(8199)
    s.Run()
}

会原样输出, 降级到1.11.5解决

回答

7

@1307super 你看下你有没有设置模板解析的分隔符号为${}?你可以打开GoFrame框架的调试模式看看具体的模板引擎对象的配置是什么:https://goframe.org/frame/g/debug

0

配置文件:

[viewer]
    paths        = "template"
    defaultFile = "index.html"
    delimiters  =  ["${", "}"]

1.11.5: image 解析正常

1.11.6: image 还是原样输出了{{.Config.redis.cache}}

1.11.7: image 还是原样输出

2

@1307super 你的模板引擎的分隔符号是这个:

image

8

非常感谢

1

请问你的模板能渲染出来吗?为什么我的模板渲染还是显示出源码,我这里没有用到解析变量只是渲染模板 2df900a5eecd78631b8686d610d53ff

4

图中的模板解析特征是 ${}