Add documentation for using layout files with templates #219
This commit is contained in:
		
				
					committed by
					
						
						Javier Provecho Fernandez
					
				
			
			
				
	
			
			
			
						parent
						
							51599d3c0a
						
					
				
				
					commit
					bee03fa7b0
				
			
							
								
								
									
										27
									
								
								README.md
									
									
									
									
									
								
							
							
						
						
									
										27
									
								
								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"}}
 | 
				
			||||||
 | 
					<html>
 | 
				
			||||||
 | 
					    <head></head>
 | 
				
			||||||
 | 
					    <body>
 | 
				
			||||||
 | 
					        {{template "content" .}}
 | 
				
			||||||
 | 
					    </body>
 | 
				
			||||||
 | 
					</html>
 | 
				
			||||||
 | 
					{{end}}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					whatever.tmpl
 | 
				
			||||||
 | 
					```html
 | 
				
			||||||
 | 
					{{define "content"}}
 | 
				
			||||||
 | 
					<h1>Hello World!</h1>
 | 
				
			||||||
 | 
					{{end}}
 | 
				
			||||||
 | 
					```
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#### Redirects
 | 
					#### Redirects
 | 
				
			||||||
 | 
					
 | 
				
			||||||
Issuing a HTTP redirect is easy:
 | 
					Issuing a HTTP redirect is easy:
 | 
				
			||||||
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user