Include.md - hugo - [fork] hugo port for 9front
HTML git clone https://git.drkhsh.at/hugo.git
DIR Log
DIR Files
DIR Refs
DIR Submodules
DIR README
DIR LICENSE
---
Include.md (2403B)
---
1 ---
2 title: partials.Include
3 description: Executes the given partial template, optionally passing context. If the partial template contains a return statement, returns the given value, else returns the rendered output.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [partial]
9 returnType: any
10 signatures: ['partials.Include NAME [CONTEXT]']
11 aliases: [/functions/partial]
12 ---
13
14 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.
15
16 [`return`]: /functions/go-template/return/
17
18 In this example we have three partial templates:
19
20 ```text
21 layouts/
22 └── _partials/
23 ├── average.html
24 ├── breadcrumbs.html
25 └── footer.html
26 ```
27
28 The "average" partial returns the average of one or more numbers. We pass the numbers in context:
29
30 ```go-html-template
31 {{ $numbers := slice 1 6 7 42 }}
32 {{ $average := partial "average.html" $numbers }}
33 ```
34
35 The "breadcrumbs" partial renders [breadcrumb navigation], and needs to receive the current page in context:
36
37 ```go-html-template
38 {{ partial "breadcrumbs.html" . }}
39 ```
40
41 The "footer" partial renders the site footer. In this contrived example, the footer does not need access to the current page, so we can omit context:
42
43 ```go-html-template
44 {{ partial "footer.html" }}
45 ```
46
47 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:
48
49 ```go-html-template
50 {{ $ctx := dict
51 "page" .
52 "name" "John Doe"
53 "major" "Finance"
54 "gpa" 4.0
55 }}
56 {{ partial "render-student-info.html" $ctx }}
57 ```
58
59 Then, within the partial template:
60
61 ```go-html-template
62 <p>{{ .name }} is majoring in {{ .major }}.</p>
63 <p>Their grade point average is {{ .gpa }}.</p>
64 <p>See <a href="{{ .page.RelPermalink }}">details.</a></p>
65 ```
66
67 To return a value from a partial template, it must contain only one `return` statement, placed at the end of the template:
68
69 ```go-html-template
70 {{ $result := "" }}
71 {{ if math.ModBool . 2 }}
72 {{ $result = "even" }}
73 {{ else }}
74 {{ $result = "odd" }}
75 {{ end }}
76 {{ return $result }}
77 ```
78
79 See [details][`return`].
80
81 [`return`]: /functions/go-template/return/
82
83 [breadcrumb navigation]: /content-management/sections/#ancestors-and-descendants
84 [details]: /functions/go-template/return/