Merge commit 'a024bc7d76fcc5e49e8210f9b0896db9ef21861a'

This commit is contained in:
Bjørn Erik Pedersen
2025-02-13 10:40:34 +01:00
817 changed files with 5301 additions and 14766 deletions

View File

@@ -1,17 +1,13 @@
---
title: Scratch
description: Returns a "scratch pad" on the given page to store and manipulate data.
description: Returns a "scratch pad" to store and manipulate data, scoped to the current page.
categories: []
keywords: []
action:
related:
- methods/page/Store
- functions/collections/NewScratch
related: []
returnType: maps.Scratch
signatures: [PAGE.Scratch]
toc: true
aliases: [/extras/scratch/,/doc/scratch/,/functions/scratch]
expiryDate: 2025-11-18 # deprecated 2024-11-18
expiryDate: 2026-11-18 # deprecated 2024-11-18 (soft)
---
{{% deprecated-in 0.138.0 %}}
@@ -23,30 +19,3 @@ Beginning with v0.138.0 the `PAGE.Scratch` method is aliased to `PAGE.Store`.
[`PAGE.Store`]: /methods/page/store/
{{% /deprecated-in %}}
The `Scratch` method on a `Page` object creates a [scratch pad](g) to store and manipulate data. To create a scratch pad that is not reset on server rebuilds, use the [`Store`] method instead.
To create a locally scoped scratch pad that is not attached to a `Page` object, use the [`newScratch`] function.
[`Store`]: /methods/page/store/
[`newScratch`]: /functions/collections/newscratch/
{{% include "methods/page/_common/scratch-methods.md" %}}
## Determinate values
The `Scratch` method is often used to set scratch pad values within a shortcode, a partial template called by a shortcode, or by a Markdown render hook. In all three cases, the scratch pad values are indeterminate until Hugo renders the page content.
If you need to access a scratch pad value from a parent template, and the parent template has not yet rendered the page content, you can trigger content rendering by assigning the returned value to a [noop](g) variable:
```go-html-template
{{ $noop := .Content }}
{{ .Store.Get "mykey" }}
```
You can also trigger content rendering with the `ContentWithoutSummary`, `FuzzyWordCount`, `Len`, `Plain`, `PlainWords`, `ReadingTime`, `Summary`, `Truncated`, and `WordCount` methods. For example:
```go-html-template
{{ $noop := .WordCount }}
{{ .Store.Get "mykey" }}
```