Skip to content

Commit

Permalink
Update partial function example
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Mar 19, 2024
1 parent e26b463 commit 55d5a27
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions content/en/functions/partials/Include.md
Expand Up @@ -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:
Expand Down

0 comments on commit 55d5a27

Please sign in to comment.