mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-14 15:54:38 -04:00
Make the recommendation to use partial over template consistent
Also, mention internal templates. Fixes https://github.com/gohugoio/hugoDocs/issues/382.
This commit is contained in:
parent
6cd260a41d
commit
d129b4a280
@ -109,24 +109,37 @@ There are more boolean operators than those listed in the Hugo docs in the [Gola
|
|||||||
|
|
||||||
## Includes
|
## Includes
|
||||||
|
|
||||||
When including another template, you will pass to it the data it will be
|
When including another template, you will need to pass it the data that it would
|
||||||
able to access. To pass along the current context, please remember to
|
need to access.
|
||||||
include a trailing dot. The templates location will always be starting at
|
|
||||||
the `/layouts/` directory within Hugo.
|
|
||||||
|
|
||||||
### Template and Partial Examples
|
{{% note %}}
|
||||||
|
To pass along the current context, please remember to include a trailing **dot**.
|
||||||
|
{{% /note %}}
|
||||||
|
|
||||||
```
|
The templates location will always be starting at the `layouts/` directory
|
||||||
{{ template "partials/header.html" . }}
|
within Hugo.
|
||||||
```
|
|
||||||
|
|
||||||
Starting with Hugo v0.12, you may also use the `partial` call
|
### Partial
|
||||||
for [partial templates][partials]:
|
|
||||||
|
The [`partial`][partials] function is used to include *partial* templates using
|
||||||
|
the syntax `{{ partial "<PATH>/<PARTIAL>.<EXTENSION>" . }}`.
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
```
|
```
|
||||||
{{ partial "header.html" . }}
|
{{ partial "header.html" . }}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### Template
|
||||||
|
|
||||||
|
The `template` function was used to include *partial* templates in much older
|
||||||
|
Hugo versions. Now it is still useful for calling [*internal*
|
||||||
|
templates][internal_templates]:
|
||||||
|
|
||||||
|
```
|
||||||
|
{{ template "_internal/opengraph.html" . }}
|
||||||
|
```
|
||||||
|
|
||||||
## Logic
|
## Logic
|
||||||
|
|
||||||
Go templates provide the most basic iteration and conditional logic.
|
Go templates provide the most basic iteration and conditional logic.
|
||||||
@ -479,6 +492,7 @@ Go allows you to do more than what's shown here. Using Hugo's [`where` function]
|
|||||||
[index]: /functions/index/
|
[index]: /functions/index/
|
||||||
[math functions]: /functions/math/
|
[math functions]: /functions/math/
|
||||||
[partials]: /templates/partials/ "Link to the partial templates page inside of the templating section of the Hugo docs"
|
[partials]: /templates/partials/ "Link to the partial templates page inside of the templating section of the Hugo docs"
|
||||||
|
[internal_templates]: /templates/internal/
|
||||||
[relpermalink]: /variables/page/
|
[relpermalink]: /variables/page/
|
||||||
[safehtml]: /functions/safehtml/
|
[safehtml]: /functions/safehtml/
|
||||||
[sitevars]: /variables/site/
|
[sitevars]: /variables/site/
|
||||||
|
@ -67,10 +67,6 @@ As shown in the above example directory structure, you can nest your directories
|
|||||||
{{ partial "footer/scripts.html" . }}
|
{{ partial "footer/scripts.html" . }}
|
||||||
```
|
```
|
||||||
|
|
||||||
{{% note %}}
|
|
||||||
Before v0.12, Hugo used the `template` call to include partial templates. When using Hugo v0.12 and newer, be sure to use the `{{ partial "<PATH>/<PARTIAL>.html" . }}` syntax. The old approach will still work but has fewer benefits.
|
|
||||||
{{% /note %}}
|
|
||||||
|
|
||||||
### Variable Scoping
|
### Variable Scoping
|
||||||
|
|
||||||
The second argument in a partial call is the variable being passed down. The above examples are passing the `.`, which tells the template receiving the partial to apply the current [context][context].
|
The second argument in a partial call is the variable being passed down. The above examples are passing the `.`, which tells the template receiving the partial to apply the current [context][context].
|
||||||
|
Loading…
x
Reference in New Issue
Block a user