Back to Hugo

Store

docs/content/en/methods/page/Store.md

0.161.11.2 KB
Original Source

Use the Store method on a Page object to create a scratch pad to store and manipulate data, scoped to the current page. To create a scratch pad with a different scope, refer to the scope section below.

{{% include "_common/store-methods.md" %}}

{{% include "_common/scratch-pad-scope.md" %}}

Determinate values

The Store method is often used to set scratch pad values within a shortcode template, a partial template called by a shortcode template, or by a render hook template. 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 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" }}