71f739460content: Reformat procedures to use description lists instead of H3 elements420a78802content: Remove 21YunBox hosting guideabeea342fcontent: Add hosting guide for Vercel3aaca6c0acontent: Add hosting guide for Renderd77b06aa6content: Fix formatting82885415fcontent: Change build.sh file perms in Cloudflare hosting docs0569c68cacontent: Fix typo8f14be5dacontent: Remove duplicate list itemse76f17815misc: Fix typo in configuration for the Markdown linter32e450b7cmisc: Fix typo in configuration for the Markdown linter81bd0056amics: Update configuration for the Markdown linter480ae9014content: Improve file names in the PageInner descriptionb17999021content: Adjust Markdown to pass linter tests1d9d56897misc: Implement Markdown linter91fc34c58content: Miscellaneous editsb7c60ae0bcontent: Add admonition for outdated learning resources51b6df588misc: Activate stale action84a897f5fmisc: Implement stale action167ea9713content: Update GitHub Pages workflow example3672d9116misc: Use actions/checkout@v5 in workflows2f2b4c968misc: Update spellcheck configs55a8ff7aecontent: Fix typo36e3d7b7bAdjust sponsors51014e6b9content: Fix link37cfc093fcontent: Add Cloudflare Worker hosting instructions09862ffadcontent: Update hosting considerations related to GitInfo477f3e7c0misc: Update cspell config7a7bb4874content: Miscellaneous edits48486d5accontent: Remove Cloudflare Pages documentation382f8052dcontent: Remove KeyCDN documentation8ecbc985ccontent: Update hosting workflow files57fd362bfcontent: Clarify applicability of the slug front matter field0dcfff9c7content: Update directory-structure.md58e3609a0content: Fix typo22fb43695content: Fix search/replace errorsfba8342a8content: Fix missing link refs97e035006Update netlify.toml6ab5ae6dfcontent: Improve GitLab Pages compression performance172bfbc4bcontent: Differentiate content view templates from other templates978770fc8content: Clarify handling of goldmark extensions conflictcb74aa4c7content: Improve Codeberg Pages hosting instructions794477792content: Add custom domain instructions to Codeberg Pages setup235fac27dcontent: Improve description of code block render hook options map35a507d31content: Improve WP2Hugo description8191f4dcfcontent: Improve WP2Hugo description25cca30fdcontent: Fix typee955652aecontent: Improve base template description922aa91bdcontent: Improve description of partial lookup logic072536ef6content: Update template type documentation5bf153531Update netlify.tomlcdd20a433content: Indicate language sort order for relevant page methodsfc9a868c9content: Add Sitepins to list of commercial CMS platformsb6077449ccontent: Update version referencesb71388caccontent: Fix typoc27dfdef3content: Move link referenced008ea6accontent: Fix typo040f14a3ccontent: Fix typo1ac119d26content: Fix typoa5a4fa907content: More updates for v0.148.0b7247a8eacontent: Remove command chaining from GitHub Actions workflow6ecb96bcdcontent: Updates for v0.148.0aea9e4c29netlify: Update Hugo version4e71546d1Add Ancestors (plural) method to GitInfo, rename Ancestor field to Parent68620a6c2source: Expose Ancestor in GitInfo git-subtree-dir: docs git-subtree-split:71f739460f
3.4 KiB
title, description, categories, keywords, params
| title | description | categories | keywords | params | |||||||
|---|---|---|---|---|---|---|---|---|---|---|---|
| Store | Returns a "scratch pad" to store and manipulate data, scoped to the current site. |
|
{{< new-in 0.139.0 />}}
Use the Store method on a Site object to create a scratch pad to store and manipulate data, scoped to the current site. To create a scratch pad with a different scope, refer to the scope section below.
Methods
Set
Sets the value of a given key.
{{ site.Store.Set "greeting" "Hello" }}
Get
Gets the value of a given key.
{{ site.Store.Set "greeting" "Hello" }}
{{ site.Store.Get "greeting" }} → Hello
Add
Adds a given value to existing value(s) of the given key.
For single values, Add accepts values that support Go's + operator. If the first Add for a key is an array or slice, the following adds will be appended to that list.
{{ site.Store.Set "greeting" "Hello" }}
{{ site.Store.Add "greeting" "Welcome" }}
{{ site.Store.Get "greeting" }} → HelloWelcome
{{ site.Store.Set "total" 3 }}
{{ site.Store.Add "total" 7 }}
{{ site.Store.Get "total" }} → 10
{{ site.Store.Set "greetings" (slice "Hello") }}
{{ site.Store.Add "greetings" (slice "Welcome" "Cheers") }}
{{ site.Store.Get "greetings" }} → [Hello Welcome Cheers]
SetInMap
Takes a key, mapKey and value and adds a map of mapKey and value to the given key.
{{ site.Store.SetInMap "greetings" "english" "Hello" }}
{{ site.Store.SetInMap "greetings" "french" "Bonjour" }}
{{ site.Store.Get "greetings" }} → map[english:Hello french:Bonjour]
DeleteInMap
Takes a key and mapKey and removes the map of mapKey from the given key.
{{ site.Store.SetInMap "greetings" "english" "Hello" }}
{{ site.Store.SetInMap "greetings" "french" "Bonjour" }}
{{ site.Store.DeleteInMap "greetings" "english" }}
{{ site.Store.Get "greetings" }} → map[french:Bonjour]
GetSortedMapValues
Returns an array of values from key sorted by mapKey.
{{ site.Store.SetInMap "greetings" "english" "Hello" }}
{{ site.Store.SetInMap "greetings" "french" "Bonjour" }}
{{ site.Store.GetSortedMapValues "greetings" }} → [Hello Bonjour]
Delete
Removes the given key.
{{ site.Store.Set "greeting" "Hello" }}
{{ site.Store.Delete "greeting" }}
{{% 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:
{{ $noop := .Content }}
{{ site.Store.Get "mykey" }}
You can also trigger content rendering with the ContentWithoutSummary, FuzzyWordCount, Len, Plain, PlainWords, ReadingTime, Summary, Truncated, and WordCount methods. For example:
{{ $noop := .WordCount }}
{{ site.Store.Get "mykey" }}