ERROR:html/template: ".../index.html" is undefined

There will be a error with loading template files as your guidance!
Maybe my error codding.
This commit is contained in:
Shuai Qi 2017-04-12 21:14:54 +08:00 committed by GitHub
parent 3b54702915
commit 029b60d02e

View File

@ -570,14 +570,15 @@ Using templates with same name in different directories
```go
func main() {
router := gin.Default()
router.LoadHTMLGlob("templates/**/*")
router.LoadHTMLGlob("templates/posts/*")
router.GET("/posts/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Posts",
})
})
router.LoadHTMLGlob("templates/users/*")
router.GET("/users/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "users/index.tmpl", gin.H{
c.HTML(http.StatusOK, "index.tmpl", gin.H{
"title": "Users",
})
})