Files
gf/.example/os/gview/bind_func/gview_func1.go

25 lines
467 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"github.com/gogf/gf/frame/g"
"github.com/gogf/gf/os/gview"
)
// 用于测试的内置函数
func funcTest() string {
return "test content"
}
func main() {
// 解析模板的时候传递模板函数映射Map仅会在当前模板解析生效
parsed, err := g.View().ParseContent(`call build-in function test: {{test}}`, nil, gview.FuncMap{
"test": funcTest,
})
if err != nil {
panic(err)
}
fmt.Println(string(parsed))
}