I feel like this is something I should be getting by this point, but…
I have a top bar section in a site I’m building that I want to show the section title if it’s in either the “tutorials” or “articles” section of the site. Right now, I have an if and if else statement that just repeats the same templating. Keep in mind this is at the page level (i.e., not on a list or node). I’ve tried the following with no luck:
{{if or (eq .Section "tutorials")(eq .Section "articles")}}
...here is some stuff to show in the top bar...
{{end}}
But I’m getting an incomplete template error in the console. I also tried with both “==” and moving the position of or. Since the top bar is used across every page, I thought maybe I needed to add a first if with .IsPage, but that still created the same error, which was a nonissue when I created the if/if else templating that is now working without issue. This is more of an attempt to make things drier than necessarily a hurdle to overcome. Thanks!
update Figured the working code might make this clearer:
{{ if and ($authors := .Params.authors) (ne $authors "none") }}
I want to with condition $authors=none strings does not processed, but they continue to be processed, although {{ printf "%S" $authors }} shows [%!S(string=none)].
Maybe it is wrong, but it works. If the $authors is not defined, strings inside the “If” are not processed. Variable $author also receives the correct value.
Just a tip: you can’t use the %s sequence to print map/slice The error you get is “%!S”, which is telling you that the parameter is not a string. Use %v instead. Examples: