Explain behaviour when appending to a slice containing other slices

This commit is contained in:
Kiran Castellino 2023-08-06 09:04:13 +10:00 committed by GitHub
parent 69e24e44e8
commit 4d95973020
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 1 deletions

View File

@ -26,4 +26,12 @@ The same example appending a slice to a slice:
{{ $s = $s | append (slice "d" "e") }}
```
If a slice contains other slices, further slices will be appended as values:
```go-html-template
{{ $s := slice (slice "a" "b") (slice "c" "d") }}
{{ $s = $s | append (slice "e" "f") (slice "g" "h") }}
{{/* $s now contains a [][]string containing four slices: ["a" "b"], ["c" "d"], ["e" "f"], and ["g" "h"] */}}
```
The `append` function works for all types, including `Pages`.

View File

@ -72,7 +72,7 @@ Get the value of a given key.
Add 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.
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](/functions/append/) to that list.
```go-html-template
{{ $scratch.Add "greetings" "Hello" }}