mirror of
https://github.com/kataras/iris.git
synced 2026-01-10 21:45:57 +00:00
update Blocks module
This commit is contained in:
@@ -8,6 +8,7 @@ func main() {
|
||||
// Note, in Blocks engine, layouts
|
||||
// are used by their base names, the
|
||||
// blocks.LayoutDir(layoutDir) defaults to "./layouts".
|
||||
// .Blocks(...).Layout("main") for default layout for all views, it can be modified through ctx.ViewLayout though.
|
||||
|
||||
app.Get("/", index)
|
||||
|
||||
|
||||
@@ -1,8 +1,3 @@
|
||||
<!-- You can define more than one block.
|
||||
The default one is "content" which should be the main template's body.
|
||||
So, even if it's missing (see index.html), it's added automatically by the view engine.
|
||||
When you need to define more than one block, you have to be more specific:
|
||||
-->
|
||||
{{ define "content" }}
|
||||
<h1>Internal Server Error</h1>
|
||||
{{ end }}
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
<title>{{.Code}}</title>
|
||||
</head>
|
||||
<body>
|
||||
{{ template "content" .}}
|
||||
{{ template "content" . }}
|
||||
|
||||
{{block "message" .}}{{end}}
|
||||
{{ block "message" . }}Default Error Message{{ end }}
|
||||
</body>
|
||||
</html>
|
||||
38
_examples/view/template_blocks_2/main.go
Normal file
38
_examples/view/template_blocks_2/main.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package main
|
||||
|
||||
import "github.com/kataras/iris/v12"
|
||||
|
||||
// Based on https://github.com/kataras/iris/issues/2214.
|
||||
func main() {
|
||||
app := initApp()
|
||||
app.Listen(":8080")
|
||||
}
|
||||
|
||||
func initApp() *iris.Application {
|
||||
app := iris.New()
|
||||
app.Logger().SetLevel("debug")
|
||||
|
||||
tmpl := iris.Blocks("./src/public/html", ".html")
|
||||
tmpl.Layout("main")
|
||||
app.RegisterView(tmpl)
|
||||
|
||||
app.Get("/list", func(ctx iris.Context) {
|
||||
ctx.View("files/list")
|
||||
})
|
||||
|
||||
app.Get("/menu", func(ctx iris.Context) {
|
||||
ctx.View("menu/menu")
|
||||
})
|
||||
|
||||
app.Get("/list2", func(ctx iris.Context) {
|
||||
ctx.ViewLayout("secondary")
|
||||
ctx.View("files/list")
|
||||
})
|
||||
|
||||
app.Get("/menu2", func(ctx iris.Context) {
|
||||
ctx.ViewLayout("secondary")
|
||||
ctx.View("menu/menu")
|
||||
})
|
||||
|
||||
return app
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{{ define "title"}}
|
||||
<title>222</title>
|
||||
{{ end }}
|
||||
|
||||
{{ define "content" }}
|
||||
<h1>List Content</h1>
|
||||
{{ end }}
|
||||
@@ -0,0 +1,8 @@
|
||||
<html>
|
||||
<head>
|
||||
{{ block "title" .}}<title>Main Default Title</title>{{end}}
|
||||
</head>
|
||||
<body>
|
||||
{{ block "content" .}}<h1>Main Default Content</h1>{{end}}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,9 @@
|
||||
<html>
|
||||
<head>
|
||||
{{ block "title" .}}<title>Secondary Default Title</title>{{end}}
|
||||
</head>
|
||||
<body>
|
||||
<h1>Secondary Layout</h1>
|
||||
{{ block "content" .}}<h1>Secondary Default Content</h1>{{end}}
|
||||
</body>
|
||||
</html>
|
||||
@@ -0,0 +1,3 @@
|
||||
{{ define "title" }} <title>111</title>{{ end }}
|
||||
|
||||
{{ define "content" }}<h1>Menu Content</h1>{{ end }}
|
||||
Reference in New Issue
Block a user