mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-18 19:04:40 -04:00
Update partial function example
This commit is contained in:
parent
e26b4634f9
commit
55d5a27871
@ -48,21 +48,24 @@ The "footer" partial renders the site footer. In this contrived example, the foo
|
|||||||
{{ partial "breadcrumbs.html" }}
|
{{ 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
|
```go-html-template
|
||||||
{{ $student := dict
|
{{ $ctx := dict
|
||||||
|
"page" .
|
||||||
"name" "John Doe"
|
"name" "John Doe"
|
||||||
"major" "Finance"
|
"major" "Finance"
|
||||||
"gpa" 4.0
|
"gpa" 4.0
|
||||||
}}
|
}}
|
||||||
{{ partial "render-student-info.html" $student }}
|
{{ partial "render-student-info.html" $ctx }}
|
||||||
```
|
```
|
||||||
|
|
||||||
Then, within the partial template:
|
Then, within the partial template:
|
||||||
|
|
||||||
```go-html-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:
|
To return a value from a partial template, it must contain only one `return` statement, placed at the end of the template:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user