| 1 |
--- |
| 2 |
title: Store |
| 3 |
description: Returns a persistent data structure for storing and manipulating keyed values, scoped to the current page. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
returnType: maps.Scratch |
| 9 |
signatures: [PAGE.Store] |
| 10 |
aliases: [/functions/store/,/extras/scratch/,/doc/scratch/,/functions/scratch] |
| 11 |
--- |
| 12 |
|
| 13 |
Use the `Store` method on a `Page` object to create a persistent data structure for storing and manipulating keyed values, scoped to the current page. To create a data structure with a different [scope](g), refer to the [scope](#scope) section below. |
| 14 |
|
| 15 |
{{% include "_common/store-methods.md" %}} |
| 16 |
|
| 17 |
{{% include "_common/store-scope.md" %}} |
| 18 |
|
| 19 |
## Determinate values |
| 20 |
|
| 21 |
The `Store` method is often used to set values within a _shortcode_ template, a _partial_ template called by a _shortcode_ template, or by a _render hook_ template. In all three cases, the stored values are indeterminate until Hugo renders the page content. |
| 22 |
|
| 23 |
If you need to access a stored 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: |
| 24 |
|
| 25 |
```go-html-template |
| 26 |
{{ $noop := .Content }} |
| 27 |
{{ .Store.Get "mykey" }} |
| 28 |
``` |
| 29 |
|
| 30 |
You can also trigger content rendering with the `ContentWithoutSummary`, `FuzzyWordCount`, `Len`, `Plain`, `PlainWords`, `ReadingTime`, `Summary`, `Truncated`, and `WordCount` methods. For example: |
| 31 |
|
| 32 |
```go-html-template |
| 33 |
{{ $noop := .WordCount }} |
| 34 |
{{ .Store.Get "mykey" }} |
| 35 |
``` |