# Understanding Hugo Conditionals

**URL:** <https://discourse.gohugo.io/t/understanding-hugo-conditionals/14476>\
**Category:** tips & tricks\
**Created:** [September 28, 2018, 7:29pm UTC](https://discourse.gohugo.io/t/understanding-hugo-conditionals/14476 "2018-09-28T19:29:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dwalkr](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/dwalkr/32/5807_2.png) [@dwalkr](https://discourse.gohugo.io/u/dwalkr)\
**Post date:** [September 28, 2018, 7:29pm UTC](https://discourse.gohugo.io/t/understanding-hugo-conditionals/14476/1 "2018-09-28T19:29:28Z")

</div>

Hey guys!

I’m sure a lot of you are Hugo experts, but I wanted to share this article with you that I wrote that discusses Hugo’s approach to templating and conditionals. When discussing Hugo with non-Hugo devs I frequently hear complaints about how “crazy” the templating system is, when I think it is easy to understand and follows a simple ruleset. I hope this article helps clear some of that up.

Check out out: [Demystifying Hugo Conditionals](https://forestry.io/blog/demystifying-hugo-conditionals/)

---

<div class="post-metadata">

**Author:** ![gaetawoo](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/gaetawoo/32/16789_2.png) [@gaetawoo](https://discourse.gohugo.io/u/gaetawoo)\
**Post date:** [September 28, 2018, 7:47pm UTC](https://discourse.gohugo.io/t/understanding-hugo-conditionals/14476/2 "2018-09-28T19:47:13Z")

</div>

thanks!

---

<div class="post-metadata">

**Author:** ![asagray](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/asagray/32/6635_2.png) [@asagray](https://discourse.gohugo.io/u/asagray)\
**Post date:** [September 30, 2018, 11:39pm UTC](https://discourse.gohugo.io/t/understanding-hugo-conditionals/14476/3 "2018-09-30T23:39:04Z")

</div>

Thanks for the article. This adds some clarity to conditional evaluation.

A question outside the scope of the article – I’m trying to understand when to use `with` vs `if`. I see them used interchangeably in several cases, yet `with` doesn’t work in this scenario:

```auto
{{ with .Resources.Match "itemName" }}
        <h2>{{ .item-name-title }}</h2>
{{ end }}

```

will error out, yet

```auto
{{ if .Resources.Match "itemName" }}
        <h2>{{ .item-name-title }}</h2>
 {{ end }}

```

will evaluate successfully. What are the parameters to determine when `if` should be used instead of `with`?

---

<div class="post-metadata">

**Author:** ![funkydan2](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.gohugo.io/funkydan2/32/5636_2.png) [@funkydan2](https://discourse.gohugo.io/u/funkydan2)\
**Post date:** [September 30, 2018, 11:46pm UTC](https://discourse.gohugo.io/t/understanding-hugo-conditionals/14476/4 "2018-09-30T23:46:19Z")

</div>

@asagray I think this is to do with the scope of `dot` when using **with** and **if**. So using **with** your code is equivalent to

```auto
<h2>{{ .Resources.Match.item-name-title</h2>

```

or maybe

```auto
<h2> {{ .itemName.item-name-title }} </h2>

```
