forked from mirror/gin
Merge branch 'vinceyuan-master' into develop
This commit is contained in:
commit
0da4558139
41
README.md
41
README.md
|
@ -439,6 +439,7 @@ func main() {
|
||||||
router.Run(":8080")
|
router.Run(":8080")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
templates/index.tmpl
|
||||||
```html
|
```html
|
||||||
<html>
|
<html>
|
||||||
<h1>
|
<h1>
|
||||||
|
@ -447,6 +448,46 @@ func main() {
|
||||||
</html>
|
</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
|
You can also use your own html template render
|
||||||
|
|
||||||
```go
|
```go
|
||||||
|
|
Loading…
Reference in New Issue