Reverse if/conditional?

Hi There,

I’m attempting to make a parameter to hide the date on certain posts.

In the post params:

showdate: false

In my template

{{ if .Params.showdate }}

{{ else }}
<span class="post-date">{{ .Date.Format "Mon, Jan 2, 2006" }}</span>
{{ end }}

Obviously this doesn’t work in the way I want it to, seeing as if is looking for a boolean of true, not false.

Is there anyway to reverse the boolean, like {{ if .Params.showdate = "false" }} or something?

Sorry if I’m missing something obvious!

1 Like

“if not”

2 Likes

Wow, that is pretty obvious… lol.

Thanks!

{{ if and (isset .Params "showdate") (not .Params.showdate) }} did the trick.

Also {{ if not .Params.showdate }} doesn’t do it on its own, @luke?

@rdwatters this should be added here :

I think it’s important this code in the docs, because I had to look in the community for the answer.

3 Likes