I need help,the gin freamework example is like this
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")
}
my Directory is
|------templates
|----users
|-----index.tmpl
|-----test.tmpl
|-----posts
|-----index.tmpl
I'm use the same like example , but I can't use c.HTML(http.StatusOK, "users/index.tmpl", gin.H{}) for find the template,it says
html/template: "users/index.tmpl" is undefined
but i use c.HTML(http.StatusOK, "test.tmpl", gin.H{}) find it successfully
can you help me .Please forgive my poor English.soory
Take a look at: https://github.com/gin-gonic/gin/blob/develop/README.md#L484
add define in users/index.tmpl: {{ define "posts/index.tmpl" }} ... {{ end }}
Yep. I've also met with this problem, solved with @aeroxlv 's solution. Templates should be pre-defined, whether they end with tmpl or html.
Most helpful comment
Take a look at: https://github.com/gin-gonic/gin/blob/develop/README.md#L484
add define in users/index.tmpl: {{ define "posts/index.tmpl" }} ... {{ end }}