From bee03fa7b0c9bf88ac211f143e90393ecc8fd4b5 Mon Sep 17 00:00:00 2001 From: techjanitor Date: Sun, 8 Mar 2015 17:24:23 +0100 Subject: [PATCH] Add documentation for using layout files with templates #219 --- README.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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"}} +

Hello World!

+{{end}} +``` + #### Redirects Issuing a HTTP redirect is easy: