mirror of
https://github.com/gohugoio/hugo.git
synced 2024-12-18 17:36:52 -05:00
5fd1e74903
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
26 lines
841 B
Markdown
26 lines
841 B
Markdown
---
|
|
title: collections.Apply
|
|
description: Returns a new collection with each element transformed by the given function.
|
|
categories: []
|
|
keywords: []
|
|
action:
|
|
aliases: [apply]
|
|
related: []
|
|
returnType: '[]any'
|
|
signatures: [collections.Apply COLLECTION FUNCTION PARAM...]
|
|
aliases: [/functions/apply]
|
|
---
|
|
|
|
The `apply` function takes three or more arguments, depending on the function being applied to the collection elements.
|
|
|
|
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.
|
|
|
|
```go-html-template
|
|
{{ $s := slice "hello" "world" }}
|
|
|
|
{{ $s = apply $s "strings.FirstUpper" "." }}
|
|
{{ $s }} → [Hello World]
|
|
|
|
{{ $s = apply $s "strings.Replace" "." "l" "_" }}
|
|
{{ $s }} → [He__o Wor_d]
|
|
```
|