How to format/beautify partail/template files?

Hello,

I’m using VSCode as code editor for working with Hugo (I’m using Visual Studio as my primary IDE, so your (probably) answer(s) can be for that too)

I have a problem, as you know, the partials/templates are html files (it can be anything but by default are html), inside this files, we use Go (I think) language too (for ex. {{ if isset ... }}), for heavy/complex templates I usually format my .html file like this:

{{ if ...}}
    <div>its just example</div>
{{ end }}

So far so good, but if I try to format my file, above format will be broken to:

{{ if ...}}<div>its just example</div>{{ end }}

I googled about that, but I found nothing, I’m not familiar with Go (and Go template), so maybe there is some extension/solution to solve this problem, if so please let me know.

Thank you!

I’m an ST3 user, so it’s unlikely that I’ll be of any help. That said, have you tried reading through the documentation for the actual VSCode plugin you’re using? I’m guessing this is what you’re currently working with:

https://marketplace.visualstudio.com/items?itemName=HookyQR.beautify

Looks like there is also a Hugo plugin for VS Code (although I appreciate this won’t take care of your beautifying needs):

https://marketplace.visualstudio.com/items?itemName=akmittal.hugofy

Other than that, perhaps a beautify/prettify plugin that accepts handlebars syntax, since my assumption would be that the plugin ignores the double curlies…

FWIW, I have this same issue with prettifying HTML in ST3 and think it’s really annoying…

Thanks, I tired both of them, first one kill my formatting as I mentioned, second one just add some short way to run Hugo command.
I’m working with handlebars (in my ASP.NET & NodeJS projects), I tired to use .hbs instead of .html for my partials, but it doesn’t help as I expected. because there is no formatter plugin that support handlebars. they are just syntax highlighter.

Linters usually have a way to avoid reformatting some specific tag.

The plugin @rdwatters mentioned does:

You might see if your linter has this kind of setting, then try getting it to take the handlebars as a tag to ignore.

1 Like

There’s a feature request on the most popular VSCode Hugo extension, “Hugo Language and Syntax Support” by @budparr.