Target conditional custom taxonomy tags?

Hello everyone,
I just started with Hugo and love it!!

I am trying to create a conditional statement that will target 2 custom taxonomy terms, I tried:

{{ if .IsNode eq .Term "foo" "bar"}}
  **Show this only if Foo or Bar are in the URL**
{{ else }}
{{ end }}

I don’t get any error’s when I run hugo server but when I visit http://localhost:1313/news/foo/ or http://localhost:1313/news/bar/ I don’t see the message that I wanted.

My config.toml setting

[taxonomies]
  foo = "foo"
  bar = "bar"

[permalinks]
  foo = "/news/:foo/"
  bar = "/news/:bar/"

Appreciate any help.

Thank you - Emma x

1 Like

Hi,

I think reading up on the syntax for conditionals would help: https://gohugo.io/templates/introduction/#example-3-and-or

Also, to help us help you more easily, could you provide more information: for example, from which layout are you calling the {{ if ... }} statement?

hi @pointyfar thanks for the reply. At the moment I have created a custom theme so just setting up the structure.

I added the code above to a partial file called test which only has that code in it and it’s being included from my baseof.html page.

Also just tried this but didn’t work :confused: :

{{ if or (or (isset .IsNode "foo") (isset .IsNode "bar")) (isset .Params "attr") }}

Got it! :smiley:

{{ if or (eq .Section "blog") (eq .Data.Singular "foo") (eq .Data.Singular "bar") }}
   Foo and Bar!
{{ else }}
{{ end }}