forked from kataras/iris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kataras#1117 from chenPengXu/master
add part function in html.go and examples
- Loading branch information
Showing
6 changed files
with
90 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{{ define "about-head"}} | ||
<title>about page</title> | ||
<style type="text/css"> | ||
body { | ||
background: #666; | ||
} | ||
</style> | ||
{{ end }} | ||
|
||
{{ define "about-body"}} | ||
extend body content in layout. | ||
{{ end }} | ||
<div> | ||
Hello about page | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{{ define "home-head"}} | ||
<title>{{.title}}</title> | ||
<style type="text/css"> | ||
body { | ||
background: #999; | ||
} | ||
</style> | ||
{{ end }} | ||
<div> | ||
Hello home page | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{{ define "user/index-head"}} | ||
<style type="text/css"> | ||
body { | ||
background: red; | ||
} | ||
</style> | ||
{{ end }} | ||
<div> | ||
Hello user index page | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters