mirror of
https://github.com/tiennm99/hugoDocs.git
synced 2026-10-14 08:18:30 +00:00
Document keyVals function
This commit is contained in:
1 parent
4dba20db35
commit
e77993be08
1 file changed
+44
@@ -0,0 +1,44 @@
|
|||||||
|
---
|
||||||
|
title: keyVals
|
||||||
|
description: Returns a KeyVals struct.
|
||||||
|
categories: [functions]
|
||||||
|
menu:
|
||||||
|
docs:
|
||||||
|
parent: functions
|
||||||
|
keywords: []
|
||||||
|
namespace: collections
|
||||||
|
relatedFuncs: []
|
||||||
|
signature:
|
||||||
|
- collections.KeyVals KEY VALUES...
|
||||||
|
- keyVals KEY VALUES...
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
The primary application for this function is the definition of the `namedSlices` parameter in the options map passed to the `.Related` method on the `Page` object.
|
||||||
|
|
||||||
|
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]
|
||||||
|
```
|
||||||
Reference in new issue
Block a user