22

How do I comment out content in Hugo?

If I have notes, unfinished thoughts, I'd like to leave them in the .md file but not have them appear in the html.

<!-- tags don't seem to work -- it doesn't even become a html comment, it remains visible text on the page.

mjeppesen
  • 1,040
  • 1
  • 10
  • 14

3 Answers3

18

Hugo uses Go templates under the hood, so the comment syntax is {{/* a comment */}}. Anything inside the comment will not be rendered to the resulting HTML files.

Official Hugo comments documentation

Henrik Aasted Sørensen
  • 6,966
  • 11
  • 51
  • 60
14

Official doc says, HTML comment does not rendered to final HTML pages.

HTML comments are by default stripped, but their content is still evaluated. That means that although the HTML comment will never render any content to the final HTML pages, code contained within the comment may fail the build process.

https://gohugo.io/templates/introduction/#html-comments-containing-go-templates

So you can use HTML comment like this

<!-- your comment text -->

Confirmed on v0.55.0

tsu1980
  • 2,472
  • 1
  • 25
  • 13
  • 1
    This does work only in *templates* but not in the *content*. The linked reference also points into the templating section. (hugo v0.104.3) – A.H. Oct 16 '22 at 11:03
12

See this example for a no-op shortcode that can be used to add comments in content files:

https://github.com/gohugoio/hugoDocs/blob/master/layouts/shortcodes/todo.html

bep
  • 1,662
  • 15
  • 16