mirror of
https://github.com/gohugoio/hugoDocs.git
synced 2025-09-13 08:06:34 -04:00
Explain behaviour when appending to a slice containing other slices
This commit is contained in:
parent
69e24e44e8
commit
4d95973020
@ -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`.
|
||||
|
@ -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" }}
|
||||
|
Loading…
x
Reference in New Issue
Block a user