mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-13 16:27:15 -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
|
||||
|
||||
When including another template, you will pass to it the data it will be
|
||||
able to access. To pass along the current context, please remember to
|
||||
include a trailing dot. The templates location will always be starting at
|
||||
the `/layouts/` directory within Hugo.
|
||||
When including another template, you will need to pass it the data that it would
|
||||
need to access.
|
||||
|
||||
### Template and Partial Examples
|
||||
{{% note %}}
|
||||
To pass along the current context, please remember to include a trailing **dot**.
|
||||
{{% /note %}}
|
||||
|
||||
```
|
||||
{{ template "partials/header.html" . }}
|
||||
```
|
||||
The templates location will always be starting at the `layouts/` directory
|
||||
within Hugo.
|
||||
|
||||
Starting with Hugo v0.12, you may also use the `partial` call
|
||||
for [partial templates][partials]:
|
||||
### Partial
|
||||
|
||||
The [`partial`][partials] function is used to include *partial* templates using
|
||||
the syntax `{{ partial "<PATH>/<PARTIAL>.<EXTENSION>" . }}`.
|
||||
|
||||
Example:
|
||||
|
||||
```
|
||||
{{ 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
|
||||
|
||||
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/
|
||||
[math functions]: /functions/math/
|
||||
[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/
|
||||
[safehtml]: /functions/safehtml/
|
||||
[sitevars]: /variables/site/
|
||||
|
@ -67,10 +67,6 @@ As shown in the above example directory structure, you can nest your directories
|
||||
{{ 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
|
||||
|
||||
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].
|
||||
@ -166,4 +162,4 @@ The following `footer.html` partial template is used for [spf13.com](http://spf1
|
||||
[lookup order]: /templates/lookup-order/ "To keep your templating dry, read the documentation on Hugo's lookup order."
|
||||
[partialcached]: /functions/partialcached/ "Use the partial cached function to improve build times in cases where Hugo can cache partials that don't need to be rendered with every page."
|
||||
[singletemps]: /templates/single-page-templates/ "The most common form of template in Hugo is the single content template. Read the docs on how to create templates for individual pages."
|
||||
[themes]: /themes/
|
||||
[themes]: /themes/
|
||||
|
Loading…
x
Reference in New Issue
Block a user