How to exclude content for a specific page (Hugo Templating)

The most current version as of .

With Hugo’s template language you can implement logical conditions into your .html files in your theme using the {{ if … }} … {{ end }} syntax to show or hide content dynamically.

So, to make use of that feature to show/hide some portions of HTML based on the current page, we can compare the current URL, stored in the .Permalink context variable to a given string of the page to apply the logic to.

To check if the URL includes th given substring, we use the in function.

And to negatate the condition we can use the not keyword:

{{ if not (in .Permalink "legal") }}
  <a href="legal.html"> Legal </a>
{{ end}}
— David Wolf