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

@@ -33,7 +33,7 @@ To create an empty map:
{{ $m := dict }}
```
Note that the `key` can be either a `string` or a `string slice`. The latter is useful to create a deeply nested structure, e.g.:
Note that the `key` can be either a `string` or a `[]string`. The latter is useful to create a deeply nested structure, e.g.:
```go-html-template
{{ $m := dict (slice "a" "b" "c") "value" }}

View File

@@ -27,6 +27,8 @@ Set `N` to zero to return an empty collection.
Use `last` and [`where`] together.
[`where`]: /functions/collections/where/
```go-html-template
{{ range where .Pages "Section" "articles" | last 5 }}
{{ .Render "summary" }}

View File

@@ -6,23 +6,22 @@ keywords: []
action:
aliases: [newScratch]
related:
- methods/page/scratch
- methods/page/store
- methods/shortcode/scratch
- methods/page/Store
- methods/site/Store
- methods/shortcode/Store
- functions/hugo/Store
returnType: maps.Scratch
signatures: [collections.NewScratch ]
toc: true
---
The `collections.NewScratch` function creates a locally scoped [scratch pad](g) to store and manipulate data. To create a scratch pad that is attached to a `Page` object, use the [`Scratch`] or [`Store`] method.
[`Scratch`]: /methods/page/scratch/
[`Store`]: /methods/page/store/
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
Sets the value of a given key.
Sets the value of the given key.
```go-html-template
{{ $s := newScratch }}
@@ -31,7 +30,7 @@ Sets the value of a given key.
###### Get
Gets the value of a given key.
Gets the value of the given key.
```go-html-template
{{ $s := newScratch }}
@@ -41,7 +40,7 @@ Gets the value of a given key.
###### Add
Adds a given value to existing value(s) of the given key.
Adds the 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.
@@ -121,3 +120,5 @@ Returns the raw backing map. Do not use with `Scratch` or `Store` methods on a `
{{ $map := $s.Values }}
```
{{% include "_common/scratch-pad-scope.md" %}}

View File

@@ -87,7 +87,7 @@ Use any of the following logical operators:
`intersect`
: (`bool`) Reports whether the given field value (a slice) contains one or more elements in common with `VALUE`. See [details](/functions/collections/intersect).
`like` {{< new-in 0.116.0 >}}
`like` {{< new-in 0.116.0 />}}
: (`bool`) Reports whether the given field value matches the regular expression specified in `VALUE`. Use the `like` operator to compare `string` values. The `like` operator returns `false` when comparing other data types to the regular expression.
{{% note %}}
@@ -168,7 +168,7 @@ For example, to return a collection of pages where any of the terms in the "genr
## Regular expression comparison
{{< new-in 0.116.0 >}}
{{< new-in 0.116.0 />}}
To return a collection of pages where the "author" page parameter begins with either "victor" or "Victor":