Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'

This commit is contained in:
Bjørn Erik Pedersen
2025-04-10 13:04:51 +02:00
987 changed files with 12379 additions and 14083 deletions

View File

@@ -3,23 +3,18 @@ title: collections.NewScratch
description: Returns a locally scoped "scratch pad" to store and manipulate data.
categories: []
keywords: []
action:
aliases: [newScratch]
related:
- methods/page/Store
- methods/site/Store
- methods/shortcode/Store
- functions/hugo/Store
returnType: maps.Scratch
signatures: [collections.NewScratch ]
toc: true
params:
functions_and_methods:
aliases: [newScratch]
returnType: maps.Scratch
signatures: [collections.NewScratch ]
---
Use the `collections.NewScratch` function to create a locally scoped [scratch pad](g) to store and manipulate data. To create a scratch pad with a different [scope](g), refer to the [scope](#scope) section below.
## Methods
###### Set
### Set
Sets the value of the given key.
@@ -28,7 +23,7 @@ Sets the value of the given key.
{{ $s.Set "greeting" "Hello" }}
```
###### Get
### Get
Gets the value of the given key.
@@ -38,7 +33,7 @@ Gets the value of the given key.
{{ $s.Get "greeting" }} → Hello
```
###### Add
### Add
Adds the given value to existing value(s) of the given key.
@@ -65,7 +60,7 @@ For single values, `Add` accepts values that support Go's `+` operator. If the f
{{ $s.Get "greetings" }} → [Hello Welcome Cheers]
```
###### SetInMap
### SetInMap
Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to the given `key`.
@@ -76,7 +71,7 @@ Takes a `key`, `mapKey` and `value` and adds a map of `mapKey` and `value` to th
{{ $s.Get "greetings" }} → map[english:Hello french:Bonjour]
```
###### DeleteInMap
### DeleteInMap
Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`.
@@ -88,7 +83,7 @@ Takes a `key` and `mapKey` and removes the map of `mapKey` from the given `key`.
{{ $s.Get "greetings" }} → map[french:Bonjour]
```
###### GetSortedMapValues
### GetSortedMapValues
Returns an array of values from `key` sorted by `mapKey`.
@@ -99,7 +94,7 @@ Returns an array of values from `key` sorted by `mapKey`.
{{ $s.GetSortedMapValues "greetings" }} → [Hello Bonjour]
```
###### Delete
### Delete
Removes the given key.
@@ -109,9 +104,9 @@ Removes the given key.
{{ $s.Delete "greeting" }}
```
###### Values
### Values
Returns the raw backing map. Do not use with `Scratch` or `Store` methods on a `Page` object due to concurrency issues.
Returns the raw backing map. Do not use with `Store` methods on a `Page` object due to concurrency issues.
```go-html-template
{{ $s := newScratch }}