mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-20 21:31:32 +02:00
Merge commit '8b9803425e63e1b1801f8d5d676e96368d706722'
This commit is contained in:
@@ -17,7 +17,7 @@ aliases: [/functions/partial]
|
||||
|
||||
Without a [`return`] statement, the `partial` function returns a string of type `template.HTML`. With a `return` statement, the `partial` function can return any data type.
|
||||
|
||||
[`return`]: /functions/go-template/return
|
||||
[`return`]: /functions/go-template/return/
|
||||
|
||||
In this example we have three partial templates:
|
||||
|
||||
@@ -48,21 +48,24 @@ The "footer" partial renders the site footer. In this contrived example, the foo
|
||||
{{ partial "breadcrumbs.html" }}
|
||||
```
|
||||
|
||||
You can pass anything in context: a page, a page collection, a scalar value, a slice, or a map. For example:
|
||||
You can pass anything in context: a page, a page collection, a scalar value, a slice, or a map. In this example we pass the current page and three scalar values:
|
||||
|
||||
```go-html-template
|
||||
{{ $student := dict
|
||||
{{ $ctx := dict
|
||||
"page" .
|
||||
"name" "John Doe"
|
||||
"major" "Finance"
|
||||
"gpa" 4.0
|
||||
}}
|
||||
{{ partial "render-student-info.html" $student }}
|
||||
{{ partial "render-student-info.html" $ctx }}
|
||||
```
|
||||
|
||||
Then, within the partial template:
|
||||
|
||||
```go-html-template
|
||||
<p>{{ .name }} is majoring in {{ .major }}. Their grade point average is {{ .gpa }}.</p>
|
||||
<p>{{ .name }} is majoring in {{ .major }}.</p>
|
||||
<p>Their grade point average is {{ .gpa }}.</p>
|
||||
<p>See <a href="{{ .page.RelPermalink }}">details.</a></p>
|
||||
```
|
||||
|
||||
To return a value from a partial template, it must contain only one `return` statement, placed at the end of the template:
|
||||
@@ -79,7 +82,7 @@ To return a value from a partial template, it must contain only one `return` sta
|
||||
|
||||
See [details][`return`].
|
||||
|
||||
[`return`]: /functions/go-template/return
|
||||
[`return`]: /functions/go-template/return/
|
||||
|
||||
[breadcrumb navigation]: /content-management/sections/#ancestors-and-descendants
|
||||
[details]: /functions/go-template/return
|
||||
[details]: /functions/go-template/return/
|
||||
|
@@ -62,4 +62,4 @@ To return a value from a partial template, it must contain only one `return` sta
|
||||
|
||||
See [details][`return`].
|
||||
|
||||
[`return`]: /functions/go-template/return
|
||||
[`return`]: /functions/go-template/return/
|
||||
|
Reference in New Issue
Block a user