aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/content/en/functions/delimit.md
blob: cc0293526da46907b95790f9a5ab14bc2d3582aa (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
---
title: delimit
description: Loops through any array, slice, or map and returns a string of all the values separated by a delimiter.
categories: [functions]
menu:
  docs:
    parent: functions
keywords: [iteration]
signature: ["delimit COLLECTION DELIMITER [LAST]"]
relatedfuncs: []
---

Delimit a slice:

```go-html-template
{{ $s := slice "b" "a" "c" }}
{{ delimit $s ", " }} → "b, a, c"
{{ delimit $s ", " " and "}} → "b, a and c"
```

Delimit a map:

{{% note %}}
The `delimit` function sorts maps by key, returning the values.
{{% /note %}}

```go-html-template
{{ $m := dict "b" 2 "a" 1 "c" 3 }}
{{ delimit $m ", " }} → "1, 2, 3"
{{ delimit $m ", " " and "}} → "1, 2 and 3"
```