Show affiliate banners, DIV elements, and shortcodes on pages with a certain category

Hi,

Is there a way to only show affiliate banners, DIV elements, and shortcodes on pages with a certain category? If so, how?

In single templateā€¦

{{ if in .Params.categories "Category A" }}
  something
{{ end }}

Thank you. It works.

And how does it work with 2 categories? (e.g., Category A and Category B)

That depends on whether you want to satisfy one condition or both.

AND

{{ if and (in .Params.categories "A") (in .Params.categories "B") }}
  something
{{ end }}

OR

{{ if or (in .Params.categories "A") (in .Params.categories "B") }}
  something
{{ end }}

The second one can also be written:

{{ if intersect .Params.categories (slice "A" "B") }}
  something
{{ end }}
2 Likes

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.