Update partial function example

This commit is contained in:
Joe Mooring 2024-03-19 08:03:42 -07:00 committed by GitHub
parent e26b4634f9
commit 55d5a27871
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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: