| 1 |
--- |
| 2 |
title: collections.KeyVals |
| 3 |
description: Returns a KeyVals struct by pairing a given key and values. |
| 4 |
categories: [] |
| 5 |
keywords: [] |
| 6 |
params: |
| 7 |
functions_and_methods: |
| 8 |
aliases: [keyVals] |
| 9 |
returnType: types.KeyValues |
| 10 |
signatures: [collections.KeyVals KEY VALUE...] |
| 11 |
aliases: [/functions/keyvals] |
| 12 |
--- |
| 13 |
|
| 14 |
The primary application for this function is the definition of the `namedSlices` value in the options map passed to the [`Related`][] method on the `Pages` object. |
| 15 |
|
| 16 |
See [related content][]. |
| 17 |
|
| 18 |
```go-html-template |
| 19 |
{{ $kv := keyVals "foo" "a" "b" "c" }} |
| 20 |
``` |
| 21 |
|
| 22 |
The resulting data structure is: |
| 23 |
|
| 24 |
```json |
| 25 |
{ |
| 26 |
"Key": "foo", |
| 27 |
"Values": [ |
| 28 |
"a", |
| 29 |
"b", |
| 30 |
"c" |
| 31 |
] |
| 32 |
} |
| 33 |
``` |
| 34 |
|
| 35 |
To extract the key and values: |
| 36 |
|
| 37 |
```go-html-template |
| 38 |
{{ $kv.Key }} → foo |
| 39 |
{{ $kv.Values }} → [a b c] |
| 40 |
``` |
| 41 |
|
| 42 |
[`Related`]: /methods/pages/related/ |
| 43 |
[related content]: /content-management/related-content/ |