pongo2 is a Django-syntax like templating-language (official website).
译文:pongo2是一种类似于Django语法的模板语言。
安装
go get -u /flosch/pongo2/v6
示例1: 渲染字符串
package main import ( "fmt" "/flosch/pongo2/v6" ) func main() { tpl, _ := pongo2.FromString("Hello {{ name }}!") ctx := pongo2.Context{ "name": "Tom", } out, _ := tpl.Execute(ctx) fmt.Println(out) // Hello Tom! }
示例1: 渲染文件
package main import ( "fmt" "/flosch/pongo2/v6" ) func main() { tpl, _ := pongo2.FromFile("example.html") ctx := pongo2.Context{ "name": "Tom", } out, _ := tpl.Execute(ctx) fmt.Println(out) }
模板 example.html
<div> Hello {{name}}! </div>
输出
<div> Hello Tom! </div>