Merge commit '8b9803425e63e1b1801f8d5d676e96368d706722'

This commit is contained in:
Bjørn Erik Pedersen
2024-06-21 09:41:24 +02:00
475 changed files with 7408 additions and 4720 deletions

View File

@@ -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&nbsp;[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/

View File

@@ -62,4 +62,4 @@ To return a value from a partial template, it must contain only one `return` sta
See&nbsp;[details][`return`].
[`return`]: /functions/go-template/return
[`return`]: /functions/go-template/return/