mirror of
https://github.com/gin-gonic/gin.git
synced 2026-01-11 00:56:57 +08:00
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:
parent
3b54702915
commit
029b60d02e
@ -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",
|
||||
})
|
||||
})
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user