Changing template content based on Taxonomy

Hi guys,

I’ve developed a custom theme for a knowledge base website that I’m working on - in the partial “footer.html” there’s a link that allows you to print the page. I use the default taxonomy “tags” to sort them in some fashion.

Is it possible in the footer.html partial to put an IF statement, where pages that are tagged with “private” display “this page cannot be printed”, but for all other pages regardless of tags it displays the print link.

Any help you can offer would be appreciated.


- private
- lorem

You can try:

{{ with .Params.tags }}
  {{ if in . "private" }}
    code displaying "this page cannot be printed"
  {{ else }}
    code displaying print link
  {{ end }}
{{ end }}

Thank you! This is exactly what I needed.

I didn’t know you could access tags through .Params like that, the documentation makes it sound like it’s only intended for accessing site settings from the config file.

There’s site.Params, and there’s also page-level .Params: Page Variables | Hugo

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