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 }}
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.
{{ 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
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?
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 }}