mirror of
https://github.com/kataras/iris.git
synced 2025-12-20 03:17:04 +00:00
add 'iris.Blocks' template engine
read more about its features at: https://github.com/kataras/blocks
This commit is contained in:
35
_examples/view/template_blocks_0/main.go
Normal file
35
_examples/view/template_blocks_0/main.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris/v12"
|
||||
|
||||
func main() {
|
||||
app := iris.New()
|
||||
// Read about its syntax at: https://github.com/kataras/blocks
|
||||
app.RegisterView(iris.Blocks("./views", ".html").Reload(true))
|
||||
|
||||
app.Get("/", index)
|
||||
app.Get("/500", internalServerError)
|
||||
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func index(ctx iris.Context) {
|
||||
data := iris.Map{
|
||||
"Title": "Page Title",
|
||||
}
|
||||
|
||||
ctx.ViewLayout("main")
|
||||
ctx.View("index", data)
|
||||
}
|
||||
|
||||
func internalServerError(ctx iris.Context) {
|
||||
ctx.StatusCode(iris.StatusInternalServerError)
|
||||
|
||||
data := iris.Map{
|
||||
"Code": iris.StatusInternalServerError,
|
||||
"Message": "Internal Server Error",
|
||||
}
|
||||
|
||||
ctx.ViewLayout("error")
|
||||
ctx.View("500", data)
|
||||
}
|
||||
Reference in New Issue
Block a user