If..Else based on frontmatter possible?

Point is:

Go Templates treat the following values as false:
false
0
any zero-length array, slice, map, or string

e.g.:

1) isset: {{ if isset .Params "foobar" }}true:{{.Params.fooBar}}{{ else }}false:{{.Params.fooBar}}{{ end }}<br/>
2) if:    {{ if .Params.fooBar }}true:{{.Params.fooBar}}{{ else }}false:{{.Params.fooBar}}{{ end }}<br/>
3) with:  {{ with .Params.fooBar }}true:{{.}}{{ end }}<br/>

(the “foobar” is not a typo - see: collections.IsSet | Hugo)

Given:

A)

---
fooBar:
---

or

---
fooBar: ""
---

you get:

1) isset: true:
2) if: false:
3) with: 

Given

B)

---
fooBar: 0
---

leads to:

1) isset: true:0
2) if: false:0
3) with: 

C)

---
fooBar: false
---
1) isset: true:false
2) if: false:false
3) with: 

So actually it does matter…

It does not, as long as you have one of those:

D)

---
---
1) isset: false:
2) if: false:
3) with: 

E)

---
fooBar: true
---
1) isset: true:true
2) if: true:true
3) with: true:true

F)

---
fooBar: 1
---
1) isset: true:1
2) if: true:1
3) with: true:1

So question is if “enable” is meant by giving just the parameter like so:

---
enableComment:
---

or actually setting a true value e.g.:

---
enableComment: true
---

In the first case it is more kind of a “flag”. The pure existence triggers an action but this may not be the common frontmatter style (?).

3 Likes