forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (39 loc) · 1.36 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"github.com/kataras/iris"
)
func main() {
app := iris.New() // defaults to these
tmpl := iris.HTML("./templates", ".html")
tmpl.Reload(true) // reload templates on each request (development mode)
// default template funcs are:
//
// - {{ urlpath "mynamedroute" "pathParameter_ifneeded" }}
// - {{ render "header.html" }}
// - {{ render_r "header.html" }} // partial relative path to current page
// - {{ yield }}
// - {{ current }}
tmpl.AddFunc("greet", func(s string) string {
return "Greetings " + s + "!"
})
app.RegisterView(tmpl)
app.Get("/", hi)
// http://localhost:8080
app.Run(iris.Addr(":8080"), iris.WithCharset("UTF-8")) // defaults to that but you can change it.
}
func hi(ctx iris.Context) {
ctx.ViewData("Title", "Hi Page")
ctx.ViewData("Name", "iris") // {{.Name}} will render: iris
// ctx.ViewData("", myCcustomStruct{})
ctx.View("hi.html")
}
/*
Note:
In case you're wondering, the code behind the view engines derives from the "github.com/kataras/iris/view" package,
access to the engines' variables can be granded by "github.com/kataras/iris" package too.
iris.HTML(...) is a shortcut of view.HTML(...)
iris.Django(...) >> >> view.Django(...)
iris.Pug(...) >> >> view.Pug(...)
iris.Handlebars(...) >> >> view.Handlebars(...)
iris.Amber(...) >> >> view.Amber(...)
*/