# Interesting unexpected with behaviour

**URL:** <https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721>\
**Category:** support\
**Created:** [September 28, 2022, 4:16pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721 "2022-09-28T16:16:48Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [September 28, 2022, 4:16pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721/1 "2022-09-28T16:16:48Z")

</div>

While working with the with command and these two different frontmatter examples :

```auto
background:
  color:

```

`background:`

```auto
{{with .Params.background.color }}
  {{.}}
{{end}}

```

will fail with the second case while the following will not.

```auto
{{with .Params.background}}
  {{with .color }}
    {{.}}
  {{end }}
{{end}}

```

Why is this important? Our CMS doesn’t add the frontmatter `color:` if it doesn’t exist. Maybe it will save someone some time.

I also didn’t expect this behaviour given with supposedly checks for existence.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 28, 2022, 4:36pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721/2 "2022-09-28T16:36:41Z")

</div>

Your 2 examples isn’t functionally the same (the first will always fail), so I’m not sure what they demonstrate.

---

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [September 28, 2022, 4:39pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721/3 "2022-09-28T16:39:19Z")

</div>

The first actually works if the frontmatter for background and color exist.

---

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [September 28, 2022, 4:45pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721/4 "2022-09-28T16:45:49Z")

</div>

Actually had an edit to make forgot .Params

---

<div class="post-metadata">

**Author:** ![tracykev](https://avatars.discourse-cdn.com/v4/letter/t/8e8cbc/32.png) [@tracykev](https://discourse.gohugo.io/u/tracykev)\
**Post date:** [September 28, 2022, 4:56pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721/5 "2022-09-28T16:56:12Z")

</div>

I will put together a demo but until then please delete this topic. It doesn’t have to do with params it has to do with a map I’m passing in to a partial but it might be the 3rd party mod we are using as well. More investigation required.

---

<div class="post-metadata">

**Author:** ![bep](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/bep/32/3332_2.png) [@bep](https://discourse.gohugo.io/u/bep)\
**Post date:** [September 28, 2022, 5:32pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721/6 "2022-09-28T17:32:13Z")

</div>

> [@tracykev](#):
>
> `{{with .Params.background.color }}`

I think you can rewrite the above to:

```auto
{{with (index .Params "background" "color") }}
{{ end }}

```

And it would work as expected. Not so pretty, but…

---

<div class="post-metadata">

**Author:** ![system](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/system/32/1_2.png) [@system](https://discourse.gohugo.io/u/system)\
**Post date:** [September 30, 2022, 5:32pm UTC](https://discourse.gohugo.io/t/interesting-unexpected-with-behaviour/40721/7 "2022-09-30T17:32:20Z")

</div>

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.
