Apply.md - hugo - [fork] hugo port for 9front
(HTM) git clone https://git.drkhsh.at/hugo.git
(DIR) Log
(DIR) Files
(DIR) Refs
(DIR) Submodules
(DIR) README
(DIR) LICENSE
---
Apply.md (858B)
---
1 ---
2 title: collections.Apply
3 description: Returns a new collection with each element transformed by the given function.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [apply]
9 returnType: '[]any'
10 signatures: [collections.Apply COLLECTION FUNCTION PARAM...]
11 aliases: [/functions/apply]
12 ---
13
14 The `apply` function takes three or more arguments, depending on the function being applied to the collection elements.
15
16 The first argument is the collection itself, the second argument is the function name, and the remaining arguments are passed to the function, with the string `"."` representing the collection element.
17
18 ```go-html-template
19 {{ $s := slice "hello" "world" }}
20
21 {{ $s = apply $s "strings.FirstUpper" "." }}
22 {{ $s }} → [Hello World]
23
24 {{ $s = apply $s "strings.Replace" "." "l" "_" }}
25 {{ $s }} → [He__o Wor_d]
26 ```