Add More Key Value Pairs to Dict

Is it possible to add more key value pairs to a dict?
My current solution is to reassign the variable:

{{ $args := dict "firstName" "Dylan" }}
{{ $args = dict "firstName" $args.firstName "lastName" "Landry" }}

I’m not sure if the append function works with dict. If not, then checkout .Scratch.SetInMap https://gohugo.io/functions/scratch/#setinmap

This is what you are looking for:

I understood (and use) append as a “if the type fits then merge it” function… But you are right, maybe it’s not working with dicts… testing.

I’ve tried the following with append and dicts, though I don’t think I am doing it right.

{{ $args = $args | append (dict "lastName" "Landry") }}
// -> error calling append: expected a slice, got map[string]interface {}
{{ $args = $args | append "lastName" "Landry" }}
// -> error calling append: expected a slice, got map[string]interface {}

Old topic but first in search results so wanted to update with solution:

{{ $myDict := (dict "key1" "value1") }}

{{ $myDict = merge $myDict (dict "key2" "value2") }}
4 Likes