How do I check for false boolean values from front matter?

I am trying to check if a certain value (custom param) from front matter is set to be false or not. How do I do that? I have a customtitle section - where I add custom title, if it is set to be false I want to use the default title.

{{if .Site.Params.customtitle }} <!-- this is checking for true, I want to check if this is false -->
    <h1 class="post-title">{{ .Title }}</h1>
{{ end }}

Does {{if not .Site.Params.customtitle }} not give the desired result?

No, it is not working :frowning:, btw I am using it as boolean straight not as a string.

I just re-read your OP. Is this a front matter variable (i.e. set per page)? If so, you shouldn’t be using .Site but .Params.customtitle. I’m pretty sure .Site.Params.customtitle is looking for a variable in your site config file.

1 Like
{{ if eq .Params.customtitle false }}
<! –– parameter set to false ––>
{{ else }}
<! –– parameter not set to false ––>
{{ end }}

The above should work. If not then you need to share your project.

Also as noted above parameters set in the project’s config are called with .Site.Params.name meanwhile parameters set in content files front are called with .Params.name

1 Like

Thank you so much :heart: @funkydan2 it works now, I did this

How do I check for false boolean values from front matter?

and it is working fine now. But the only thing which is going to bother me is that now every time I’ve to use customtitle:false for other front matter as well.

I declared customtitle so as the make pages which can have page title as title, and not as the default page h1. Is there anything else I could do?

Thank you @alexandros :heart:, I did the same and now it is working fine! But there’s an issue or a thing which I think needs improvement. Here is it: How do I check for false boolean values from front matter?

If I understand you right, you want to perform the check only on pages that already have the customtitle parameter.

You need to wrap the above code block in one more condition to check for the existence of the parameter. Something like:

{{ with .Params.customtitle }}
{{ if eq . false }}
<! –– parameter set to false ––>
{{ else }}
<! –– parameter not set to false ––>
{{ end }}
{{ end }}

In the above note the use of the dot . since with the outer check we are already within the parameter’s context.

If you need to have a further condition for pages that do not contain the customtitle parameter then you simply need to enter one more condition like so:

{{ with .Params.customtitle }}
{{ if eq . false }}
<! –– parameter set to false ––>
{{ else }}
<! –– parameter not set to false ––>
{{ end }}
{{ else }}
<! –– template logic for pages that do not have the customtitle parameter ––>
{{ end }}
2 Likes

Thank you so much :heart: @alexandros