mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-15 10:14:53 +00:00
Explain behaviour when appending to a slice containing other slices
This commit is contained in:
1 parent
69e24e44e8
commit
4d95973020
2 files changed
+9
-1
No files matched your search
@@ -26,4 +26,12 @@ The same example appending a slice to a slice:
|
|||||||
{{ $s = $s | append (slice "d" "e") }}
|
{{ $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`.
|
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.
|
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
|
```go-html-template
|
||||||
{{ $scratch.Add "greetings" "Hello" }}
|
{{ $scratch.Add "greetings" "Hello" }}
|
||||||
|
|||||||
Reference in new issue
Block a user