aboutsummaryrefslogtreecommitdiffhomepage
path: root/docs/content/en/functions/collections/KeyVals.md
blob: 3d21ca6fd8661d24bcaaacda7fec38df1a6b1848 (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
32
33
34
35
36
37
38
39
40
41
42
43
---
title: collections.KeyVals
description: Returns a KeyVals struct.
categories: []
keywords: []
action:
  aliases: [keyVals]
  related:
    - methods/pages/Related
  returnType: types.KeyValues
  signatures: [collections.KeyVals KEY VALUES...]
aliases: [/functions/keyvals]
---

The primary application for this function is the definition of the `namedSlices` parameter in the options map passed to the [`Related`] method on the `Pages` object.

[`Related`]: /methods/pages/related

See [related content](/content-management/related).

```go-html-template
{{ $kv := keyVals "foo" "a" "b" "c" }}
```

The resulting data structure is:

```json
{
  "Key": "foo",
  "Values": [
    "a",
    "b",
    "c"
  ]
}
```

To extract the key and values:

```go-html-template
{{ $kv.Key }} → foo
{{ $kv.Values }} → [a b c]
```