Explain behaviour when appending to a slice containing other slices

This commit is contained in:
Kiran Castellino authored and GitHub committed 2023-08-05 16:04:13 -07:00
1 parent 69e24e44e8
commit 4d95973020
2 files changed
+9 -1

No files matched your search

+8
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`.
+1 -1
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" }}