Function for key and value from a dict?

Given the following in front matter:

mySettings:
  - short1: "Long String 1"
  - short2: "Long String 2"
  - short3: "Long String 3"

Creates a dict with key = mySettings and a value which is a slice of dict objects. Easy enough to range over the slice:

{{- range $mySettingsDict := .Params.mySettings -}}

where in each loop $mySettingsDict is a dict, but only has one key/value in it. I know I can range (again) on this to get the values:

{{- range $key, $value := $mySettingsDict -}}

but since I know there’s only one item in it, am I missing another function that would pull out the values (since the keys are unknown)?

tryed this?

{{- range $key, $value := .Params.mySettings -}}

The two steps are required, because mySettings is an ordered array, with each element of the array being a map/dict. Hence the second range mentioned in my op.

It just seems like overkill to create another loop just to get the key/value for a dict that I know only has one item. Guess I didn’t miss anything.

1 Like

Are you sure this is not a design fault?

By the design, you know only (and want) only one item. Then why do you bother to treat it as a slice or dict? Why don’t just use it out of the box like this {{ .Params.mySettings }}?