Add documentation for using layout files with templates #219

This commit is contained in:
techjanitor 2015-03-08 17:24:23 +01:00 committed by Javier Provecho Fernandez
parent 51599d3c0a
commit bee03fa7b0
1 changed files with 27 additions and 0 deletions

View File

@ -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"}}
<html>
<head></head>
<body>
{{template "content" .}}
</body>
</html>
{{end}}
```
whatever.tmpl
```html
{{define "content"}}
<h1>Hello World!</h1>
{{end}}
```
#### Redirects
Issuing a HTTP redirect is easy: