add template_html_5 for fund part in html.go

Former-commit-id: f2143a7aded3c026da5eb0755630e7dd2cb0f874
This commit is contained in:
chenPengXu 2018-10-26 14:15:29 +08:00
parent de5be10955
commit b5a4cf901d
5 changed files with 77 additions and 0 deletions

View File

@ -0,0 +1,31 @@
package main
import (
"github.com/kataras/iris"
)
func main() {
app := iris.New()
app.RegisterView(iris.HTML("./views", ".html").Layout("layout.html"))
// TIP: append .Reload(true) to reload the templates on each request.
app.Get("/home", func(ctx iris.Context) {
ctx.ViewData("title", "Home page");
ctx.View("home.html")
// Note that: you can pass "layout" : "otherLayout.html" to bypass the config's Layout property
// or view.NoLayout to disable layout on this render action.
// third is an optional parameter
})
app.Get("/about", func(ctx iris.Context) {
ctx.View("about.html")
})
app.Get("/user/index", func(ctx iris.Context) {
ctx.View("user/index.html")
})
// http://localhost:8080
app.Run(iris.Addr(":8080"))
}

View File

@ -0,0 +1,14 @@
{{ define "about-head"}}
<style type="text/css">
body {
background: #666;
}
</style>
{{ end }}
{{ define "about-body"}}
extend body content in layout.
{{ end }}
<div>
Hello about page
</div>

View File

@ -0,0 +1,11 @@
{{ define "home-head"}}
<title>{{.title}}</title>
<style type="text/css">
body {
background: #999;
}
</style>
{{ end }}
<div>
Hello home page
</div>

View File

@ -0,0 +1,11 @@
<html>
<head>
{{ part "head" }}
</head>
<body>
<h1>[layout] Body content is below...</h1>
{{ part "body" }}
<!-- Render the current template here -->
{{ yield }}
</body>
</html>

View File

@ -0,0 +1,10 @@
{{ define "user/index-head"}}
<style type="text/css">
body {
background: red;
}
</style>
{{ end }}
<div>
Hello user index page
</div>