How to add comments in a template?

Why would you put HTML comment inside the Go template comment block… even this (yes, multi-line!) works great:

{{/* my 
multi-line
comment */}}
{{- $foo := "whatever non-comment stuff that follows" }}
1 Like

Oh, as i said, just because my editor VSC (visual studio code) colorize only HTML and not the hugo comments. Just that :frowning:

Edit : If I had the go-html-template lexer colorisation results in VSC I would be happy …

Ah, OK, sorry, missed that :slight_smile:

No problem at all @kaushalmodi … thank you for your comment, makes me think I should investigate in colorizing my code instead of changing it :slight_smile:

Edit : Works fine if I manually change the file type for template from HTML to Go … Have to do it each time, but it’s nice. Thanks for the remark, I (re) changed it for a cleaner syntax.

That’s where workspace settings come in handy. In your project’s root create a folder .vscode with a file called settings.json. To associate *.html files with gohtml add:

{
  "files.associations": {
    "*.html": "gohtml"
  }
}
3 Likes

Go HTML is an addin for VS Code. My html template files were defaulting to Handlebars which isn’t that bad (that’s because I already had the handlebars addin installed). But I’ve just installed the Go Templates addin and it does look a little better.

As @holehan points out, you can use workspace settings to make this the default for just your Hugo projects.

If you don’t already have it, you might want to install the “Better TOML” addin as well. Also “hugofy” has some actions like creating posts, sites, etc.

Some markdown addins are also useful.

1 Like

You can, of course, also do settings at the folder level.

1 Like

Whoaaa …
gotemplate-syntax plugin + .vscode/settings.json trick works like a charm. Very nice colorization.
Thanks a lot all @holehan @TotallyInformation @kaushalmodi

1 Like