From 4d959730206486ef63d36f95c00fe61775fa798e Mon Sep 17 00:00:00 2001 From: Kiran Castellino <57894504+kcastellino@users.noreply.github.com> Date: Sun, 6 Aug 2023 09:04:13 +1000 Subject: [PATCH] Explain behaviour when appending to a slice containing other slices --- content/en/functions/append.md | 8 ++++++++ content/en/functions/scratch.md | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/content/en/functions/append.md b/content/en/functions/append.md index 626bc1242..6d7ffa245 100644 --- a/content/en/functions/append.md +++ b/content/en/functions/append.md @@ -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`. diff --git a/content/en/functions/scratch.md b/content/en/functions/scratch.md index 2e00f41bd..16e502b84 100644 --- a/content/en/functions/scratch.md +++ b/content/en/functions/scratch.md @@ -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" }}