Merging maps in Hugo

I wonder if there is some hidden gem, a function I don’t know about to efficiently merge two maps together in Hugo.

Now that returning partials are there, nothing can stop us from creating our own Go Gemplate merging « function » but I’d rather use something written in Go and tested by Hugo.

1 Like

I don’t think so. We do map merges internally in Hugo (config etc), but I don’t think we have a “maps.Merge” function … Which we could add I guess… I guess it is doable in templates (using Scratch), but it gets ugly when you have to recurse.

1 Like

SYes I built a flat merge returning partial and guess I could right a deep merge with recursing partials…

But with return partials a lot of people will start manipulating data and a built in merging solution would be more than welcome.

I can add an issue later today.

1 Like

I would do it with an inline “define template”, which makes it a little more obvious when you read it.

I didn’t think inline defined templates could also return :slight_smile:

Why would you need to return? I was talking about a partial with a “recursive inline template”; you are modifiying a map, so no need to return from that recursive … thing. But it’s much easier to do in Go.