router.LoadHTMLGlob("templates/**/*")
router.GET("/posts/index", func(c *gin.Context) {
c.HTML(http.StatusOK, "posts/index.tmpl", gin.H{
"title": "Posts",
})
c.HTML(http.StatusOK, "users/index.tmpl", gin.H{
"title": "Users",
})
}
按照文档上的例子 "users/index.tmpl" 这种name 会生成index.tmpl
源码实现是 ‘name := filepath.Base(filename)’
有疑问加站长微信联系(非本文作者)