Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a map deep merging function. #5992

Closed
regisphilibert opened this issue May 28, 2019 · 1 comment

Comments

@regisphilibert
Copy link

commented May 28, 2019

As return partials become more and more popular users need for safely manipulating data will grow.

First use case I can think of is for declaring defaults vs bespoke arguments in a partial, and gracefully merge the later with the former, but I can see so much more.

It would be interesting for Hugo to provide a safe deep merge solution so users don't need to build their own.

I don't think we need this to work with raw Page context, users can always reshape their data inside custom maps.

Examples follow.

{{ $default := dict "title" .Title }}
{{ $bespoke = maps.Merge $default .Params }}

{{/* In a partial context /*}} 
{{ $default := (site.GetPage "default").Params }}
{{ $bespoke := maps.Merge $default . }}

@bep bep added this to the v0.56 milestone May 28, 2019

@bep bep added the Enhancement label May 28, 2019

@carlmjohnson

This comment has been minimized.

Copy link

commented Jul 9, 2019

In general, simpler tools for mutating dicts would be appreciated. See, e.g, this LD-JSON file where I was having some issues with bad escaping (Go thinks the LD-JSON is JavaScript and escapes it in a way that Google does not understand), so I decided to do things the "safe" way by building one big dict and writing the whole thing out at once. That works, but the code is very ugly because there's no simple way to just mutate a dict in place. Instead I use a scratch.

bep added a commit to bep/hugo that referenced this issue Jul 11, 2019

bep added a commit to bep/hugo that referenced this issue Jul 14, 2019

bep added a commit to bep/hugo that referenced this issue Jul 14, 2019

bep added a commit to bep/hugo that referenced this issue Jul 14, 2019

tpl/collections: Add Merge function
Merges two maps recursively and returns a new one. Merge is case-insensitive.

Fixes gohugoio#5992

bep added a commit to bep/hugo that referenced this issue Jul 15, 2019

tpl/collections: Add Merge function
Merges two maps recursively and returns a new one. Merge is case-insensitive.

Fixes gohugoio#5992

@bep bep closed this in #6086 Jul 15, 2019

bep added a commit that referenced this issue Jul 15, 2019

tpl/collections: Add Merge function
Merges two maps recursively and returns a new one. Merge is case-insensitive.

Fixes #5992

@gcushen gcushen referenced this issue Jul 27, 2019

Open

Theme parsing improvements #1091

1 of 6 tasks complete
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.