Comments in Hugo Templates

18 Feb 2024 18 Feb 2024 1 min read Hugo

Comments in Hugo templates can be defined with (no whitespace trimming):


{{/* This is a comment. */}}

Or (with whitespace trimming):


{{- /* This is a comment. */ -}}

You can also combine these two:


{{/* This is a comment. */ -}}
{{- /* This is a comment. */}}

As with all Hugo template blocks, a hyphen (-) trims all whitespace before or after the block.

Warning

These two variants are only supported ways. Note especially that neither {{ /* nor */ }} are valid (with a space).

Note

You can also use HTML comments which basically function like {{/* ... */}} (i.e. without whitespace trimming).