Merge 7229c488e80e33fa1bedf1a02a4584a4cd166d38 into 52fcc5dbf6e94df33ad313858fb94b713e9d1b4a

This commit is contained in:
Vince Yuan 2015-09-25 10:25:51 +00:00
commit 380d66049d

View File

@ -438,6 +438,7 @@ func main() {
router.Run(":8080")
}
```
templates/index.tmpl
```html
<html><h1>
{{ .title }}
@ -445,6 +446,46 @@ func main() {
</html>
```
Using templates with same name in different directories
```go
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/**/*")
router.GET("/posts/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{
"title": "Posts",
})
})
router.GET("/users/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "users/index.tmpl", gin.H{
"title": "Users",
})
})
router.Run(":8080")
}
```
templates/posts/index.tmpl
```html
{{ define "posts/index.tmpl" }}
<html><h1>
{{ .title }}
</h1>
<p>Using posts/index.tmpl</p>
</html>
{{ end }}
```
templates/users/index.tmpl
```html
{{ define "users/index.tmpl" }}
<html><h1>
{{ .title }}
</h1>
<p>Using users/index.tmpl</p>
</html>
{{ end }}
```
You can also use your own html template render
```go