mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-21 21:35:28 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -3,18 +3,11 @@ title: partials.IncludeCached
|
||||
description: Executes the given template and caches the result, optionally passing context. If the partial template contains a return statement, returns the given value, else returns the rendered output.
|
||||
categories: []
|
||||
keywords: []
|
||||
action:
|
||||
aliases: [partialCached]
|
||||
related:
|
||||
- functions/go-template/return
|
||||
- functions/partials/Include
|
||||
- functions/go-template/template
|
||||
- methods/page/Render
|
||||
returnType: any
|
||||
signatures: ['partials.IncludeCached LAYOUT CONTEXT [VARIANT...]']
|
||||
signatures:
|
||||
- partials.IncludeCached NAME CONTEXT [VARIANT...]
|
||||
- partialCached NAME CONTEXT [VARIANT...]
|
||||
params:
|
||||
functions_and_methods:
|
||||
aliases: [partialCached]
|
||||
returnType: any
|
||||
signatures: ['partials.IncludeCached LAYOUT CONTEXT [VARIANT...]']
|
||||
aliases: [/functions/partialcached]
|
||||
---
|
||||
|
||||
@@ -22,11 +15,10 @@ Without a [`return`] statement, the `partialCached` function returns a string of
|
||||
|
||||
The `partialCached` function can offer significant performance gains for complex templates that don't need to be re-rendered on every invocation.
|
||||
|
||||
{{% note %}}
|
||||
Each Site (or language) has its own `partialCached` cache, so each site will execute a partial once.
|
||||
|
||||
Hugo renders pages in parallel, and will render the partial more than once with concurrent calls to the `partialCached` function. After Hugo caches the rendered partial, new pages entering the build pipeline will use the cached result.
|
||||
{{% /note %}}
|
||||
> [!note]
|
||||
> Each Site (or language) has its own `partialCached` cache, so each site will execute a partial once.
|
||||
>
|
||||
> Hugo renders pages in parallel, and will render the partial more than once with concurrent calls to the `partialCached` function. After Hugo caches the rendered partial, new pages entering the build pipeline will use the cached result.
|
||||
|
||||
Here is the simplest usage:
|
||||
|
||||
@@ -36,9 +28,9 @@ Here is the simplest usage:
|
||||
|
||||
Pass additional arguments to `partialCached` to create variants of the cached partial. For example, if you have a complex partial that should be identical when rendered for pages within the same section, use a variant based on section so that the partial is only rendered once per section:
|
||||
|
||||
{{< code file=partial-cached-example.html >}}
|
||||
```go-html-template {file="layouts/_default/baseof.html"}
|
||||
{{ partialCached "footer.html" . .Section }}
|
||||
{{< /code >}}
|
||||
```
|
||||
|
||||
Pass additional arguments, of any data type, as needed to create unique variants:
|
||||
|
||||
@@ -46,7 +38,7 @@ Pass additional arguments, of any data type, as needed to create unique variants
|
||||
{{ partialCached "footer.html" . .Params.country .Params.province }}
|
||||
```
|
||||
|
||||
The variant arguments are not available to the underlying partial template; they are only used to create unique cache keys.
|
||||
The variant arguments are not available to the underlying partial template; they are only used to create unique cache keys.
|
||||
|
||||
To return a value from a partial template, it must contain only one `return` statement, placed at the end of the template:
|
||||
|
||||
|
Reference in New Issue
Block a user