mirror of
https://github.com/kataras/iris.git
synced 2025-12-24 05:17:03 +00:00
minor
Former-commit-id: 491a1001aff9fc63a0d79efbfee6a78ca711f07c
This commit is contained in:
55
_examples/view/template_jet_3/main.go
Normal file
55
_examples/view/template_jet_3/main.go
Normal file
@@ -0,0 +1,55 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/kataras/iris/v12"
|
||||
"github.com/kataras/iris/v12/view"
|
||||
)
|
||||
|
||||
// https://github.com/kataras/iris/issues/1443
|
||||
|
||||
func main() {
|
||||
|
||||
tmpl := iris.Jet("./views", ".jet")
|
||||
tmpl.Reload(true)
|
||||
|
||||
val := reflect.ValueOf(ViewBuiler{})
|
||||
fns := val.Type()
|
||||
for i := 0; i < fns.NumMethod(); i++ {
|
||||
method := fns.Method(i)
|
||||
tmpl.AddFunc(strings.ToLower(method.Name), val.Method(i).Interface())
|
||||
}
|
||||
|
||||
app := iris.New()
|
||||
app.RegisterView(tmpl)
|
||||
|
||||
app.Get("/", func(ctx iris.Context) {
|
||||
ctx.View("index.jet")
|
||||
})
|
||||
|
||||
app.Run(iris.Addr(":8080"))
|
||||
}
|
||||
|
||||
type ViewBuiler struct {
|
||||
}
|
||||
|
||||
func (ViewBuiler) Asset(a view.JetArguments) reflect.Value {
|
||||
path := a.Get(0).String()
|
||||
// fmt.Println(os.Getenv("APP_URL"))
|
||||
return reflect.ValueOf(path)
|
||||
}
|
||||
|
||||
func (ViewBuiler) Style(a view.JetArguments) reflect.Value {
|
||||
path := a.Get(0).String()
|
||||
s := fmt.Sprintf(`<link href="%v" rel="stylesheet"> `, path)
|
||||
return reflect.ValueOf(s)
|
||||
}
|
||||
|
||||
func (ViewBuiler) Script(a view.JetArguments) reflect.Value {
|
||||
path := a.Get(0).String()
|
||||
s := fmt.Sprintf(`<script src="%v" ></script>`, path)
|
||||
return reflect.ValueOf(s)
|
||||
}
|
||||
Reference in New Issue
Block a user