mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
5fd1e74903
``` git subtree add --prefix=docs/ https://github.com/gohugoio/hugoDocs.git master --squash ``` Closes #11925
43 lines
820 B
Markdown
43 lines
820 B
Markdown
---
|
|
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]
|
|
```
|