github.com/gogf/gf@v1.16.9/.example/os/gview/include/main.go (about)

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  
     6  	"github.com/gogf/gf/frame/g"
     7  	"github.com/gogf/gf/os/gfile"
     8  )
     9  
    10  func main() {
    11  	v := g.View()
    12  	// 设置模板目录为当前main.go所在目录下的template目录
    13  	v.AddPath(gfile.MainPkgPath() + gfile.Separator + "template2")
    14  	b, err := v.Parse("index.html", map[string]interface{}{
    15  		"k": "v",
    16  	})
    17  	if err != nil {
    18  		panic(err)
    19  	}
    20  	fmt.Println(string(b))
    21  }