blob: 687d8b0c89c70d52bd67207bcfe2f2dab4f264c4 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
|
---
title: template
description: Executes the given template, optionally passing context.
categories: []
keywords: []
action:
aliases: []
related:
- functions/go-template/define
- functions/partials/Include
- functions/partials/IncludeCached
returnType:
signatures: ['template NAME [CONTEXT]']
---
Use the `template` function to execute [embedded templates]. For example:
```go-html-template
{{ range (.Paginate .Pages).Pages }}
<h2><a href="{{ .RelPermalink }}">{{ .LinkTitle }}</a></h2>
{{ end }}
{{ template "_internal/pagination.html" . }}
```
You can also use the `template` function to execute a defined template:
```go-html-template
{{ template "foo" (dict "answer" 42) }}
{{ define "foo" }}
{{ printf "The answer is %v." .answer }}
{{ end }}
```
The example above can be rewritten using an [inline partial] template:
```go-html-template
{{ partial "inline/foo.html" (dict "answer" 42) }}
{{ define "partials/inline/foo.html" }}
{{ printf "The answer is %v." .answer }}
{{ end }}
```
{{% include "functions/go-template/_common/text-template.md" %}}
[`partial`]: /functions/partials/include/
[inline partial]: /templates/partials/#inline-partials
[embedded templates]: /templates/embedded/
|