diff --git a/README.md b/README.md index 92d6a0ba..83055786 100644 --- a/README.md +++ b/README.md @@ -439,6 +439,33 @@ func main() { } ``` +#####Using layout files with templates +```go +var baseTemplate = "main.tmpl" + +r.GET("/", func(c *gin.Context) { + r.SetHTMLTemplate(template.Must(template.ParseFiles(baseTemplate, "whatever.tmpl"))) + c.HTML(200, "base", data) +}) +``` +main.tmpl +```html +{{define "base"}} + +
+ + {{template "content" .}} + + +{{end}} +``` +whatever.tmpl +```html +{{define "content"}} +