Welcome to mirror list, hosted at ThFree Co, Russian Federation.

merge.md « functions « en « content « docs - github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: cea93c53a69630f925a796f01af7db752411e409 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---
title: merge
description: "`merge` deep merges two maps and returns the resulting map."
date: 2019-08-08
categories: [functions]
menu:
  docs:
    parent: "functions"
keywords: [dictionary]
signature: ["$params :=  merge $default_params $user_params"]
workson: []
hugoversion: "0.56.0"
relatedfuncs: [dict, append, reflect.IsMap, reflect.IsSlice]
aliases: []
---

An example merging two maps.

```go-html-template
{{ $default_params := dict "color" "blue" "width" "50%" "height" "25%" }}
{{ $user_params := dict "color" "red" "extra" (dict "duration" 2) }}
{{ $params := merge $default_params $user_params }}
```

Resulting __$params__:

```
"color": "red"
"extra":
  "duration": 2
"height": "25%"
"icon": "mail"
"width": "50%"
```

{{% note %}}
  Regardless of depth, merging only applies to maps. For slices, use [append]({{< ref "functions/append" >}})
{{% /note %}}