推荐一个动态模板引擎库

🎉🎉🎉

项目地址:github.com/lmmfy/goejs

魔改了 ejs 作为模板,用 otto 解释,这样可以在业务中实现非常动态灵活的输出,你可以把上下文作为一个 json 传到 ejs 中。

// default
e := otto.NewDefaultOttoEngine()
got, _ := e.Exec("hello, <%= name %>!", map[string]interface{}{"name": "goejs"}, &contract.Option{
    Debug: true,
})
fmt.Println(got) // hello, goejs!

// config 
e := otto.NewOttoEngine(ejs.NewJsScript(ejs.WithOpenDelimiter("{"), ejs.WithOpenDelimiter("}")))
got, _ := e.Exec("hello, {%= name %}!", map[string]interface{}{"name": "goejs"}, &contract.Option{
    Debug: true,
})
fmt.Println(got) // hello, goejs!
讨论数量: 0
(= ̄ω ̄=)··· 暂无内容!

讨论应以学习和精进为目的。请勿发布不友善或者负能量的内容,与人为善,比聪明更重要!