mirror of
				https://github.com/gohugoio/hugo.git
				synced 2024-05-11 05:54:58 +00:00 
			
		
		
		
	
		
			
				
	
	
	
		
			1.7 KiB
		
	
	
	
	
	
	
	
			
		
		
	
	
			1.7 KiB
		
	
	
	
	
	
	
	
title, linkTitle, description, categories, keywords, menu, function, relatedFunctions, aliases
| title | linkTitle | description | categories | keywords | menu | function | relatedFunctions | aliases | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| partials.Include | partial | Executes the named partial template. If the partial contains a return statement, returns that value, else returns the rendered output. | 
 | 
 | 
 | 
 | 
 | 
In this example we have three partial templates:
layouts/
└── partials/
    ├── average.html
    ├── breadcrumbs.html
    └── footer.html
The "average" partial returns the average of one or more numbers. We pass the numbers in context:
{{ $numbers := slice 1 6 7 42 }}
{{ $average := partial "average.html" $numbers }}
The "breadcrumbs" partial renders breadcrumb navigation, and needs to receive the current page in context:
{{ partial "breadcrumbs.html" . }}
The "footer" partial renders the site footer. In this contrived example, the footer does not need access to the current page, so we can omit context:
{{ partial "breadcrumbs.html" }}
You can pass anything in context: a page, a page collection, a scalar value, a slice, or a map. For example:
{{ $student := dict 
  "name" "John Doe" 
  "major" "Finance"
  "gpa" 4.0
}}
{{ partial "render-student-info.html" $student }}
Then, within the partial template:
<p>{{ .name }} is majoring in {{ .major }}. Their grade point average is {{ .gpa }}.</p>