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

     1  package main
     2  
     3  import (
     4  	"github.com/gogf/gf/frame/g"
     5  )
     6  
     7  type T struct {
     8  	Name string
     9  }
    10  
    11  func (t *T) Hello(name string) string {
    12  	return "Hello " + name
    13  }
    14  
    15  func (t *T) Test() string {
    16  	return "This is test"
    17  }
    18  
    19  func main() {
    20  	t := &T{"John"}
    21  	v := g.View()
    22  	content := `{{.t.Hello "there"}}, my name's {{.t.Name}}. {{.t.Test}}.`
    23  	if r, err := v.ParseContent(content, g.Map{"t": t}); err != nil {
    24  		g.Dump(err)
    25  	} else {
    26  		g.Dump(r)
    27  	}
    28  }