mirror of
https://github.com/kataras/iris.git
synced 2026-01-07 12:07:28 +00:00
create the new FileServer and HandleDir, deprecate the rest APIBuilder/Party static methods and more
relative: https://github.com/kataras/iris/issues/1283 and removing pongo2 from vendor: https://github.com/kataras/iris/issues/1284 Former-commit-id: 3ec57b349f99faca2b8e36d9f7252db0b6ea080d
This commit is contained in:
44
_examples/view/template_django_0/main.go
Normal file
44
_examples/view/template_django_0/main.go
Normal file
@@ -0,0 +1,44 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"github.com/kataras/iris"
|
||||
|
||||
// optionally, registers filters like `timesince`.
|
||||
_ "github.com/flosch/pongo2-addons"
|
||||
)
|
||||
|
||||
var startTime = time.Now()
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
|
||||
tmpl := iris.Django("./templates", ".html")
|
||||
tmpl.Reload(true) // reload templates on each request (development mode)
|
||||
tmpl.AddFunc("greet", func(s string) string { // {{greet(name)}}
|
||||
return "Greetings " + s + "!"
|
||||
})
|
||||
|
||||
// tmpl.RegisterFilter("myFilter", myFilter) // {{"simple input for filter"|myFilter}}
|
||||
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")
|
||||
// ctx.ViewData("serverStartTime", startTime)
|
||||
// or if you set all view data in the same handler you can use the
|
||||
// iris.Map/pongo2.Context/map[string]interface{}, look below:
|
||||
|
||||
ctx.View("hi.html", iris.Map{
|
||||
"title": "Hi Page",
|
||||
"name": "iris",
|
||||
"serverStartTime": startTime,
|
||||
})
|
||||
}
|
||||
Reference in New Issue
Block a user