diff --git a/README.md b/README.md index 01955567..de79ec16 100644 --- a/README.md +++ b/README.md @@ -401,6 +401,7 @@ func main() { router.Run(":8080") } ``` +templates/index.tmpl ```html

{{ .title }} @@ -408,6 +409,46 @@ func main() { ``` +Using templates with same name in different directories + +```go +func main() { + router := gin.Default() + router.LoadHTMLGlob("templates/**/*") + router.GET("/post/index", func(c *gin.Context) { + c.HTML(http.StatusOK, "post/index.tmpl", gin.H{ + "title": "Posts", + }) + }) + router.GET("/user/index", func(c *gin.Context) { + c.HTML(http.StatusOK, "user/index.tmpl", gin.H{ + "title": "Users", + }) + }) + router.Run(":8080") +} +``` +templates/post/index.tmpl +```html +{{ define "post/index.tmpl" }} +

+ {{ .title }} +

+

Using post/index.tmpl

+ +{{ end }} +``` +templates/user/index.tmpl +```html +{{ define "user/index.tmpl" }} +

+ {{ .title }} +

+

Using user/index.tmpl

+ +{{ end }} +``` + You can also use your own html template render ```go