Lesson 27 - Formatting inside vs code

This is one of the html layouts. As you can see on bottom right, it’s set to nunjucks formatting.

When I save, the formatting totally changes.

It’s pretty annoying. How do I fix this?

What Nunjucks extension are you using? There are several. The most popular one does not have a formatter. Try one of the others that does come with a formatter.

You can try turning off the Format on Save setting in VS Code.

I personally write Nunjucks templates in HTML mode and use the built-in HTML formatter not Prettier. Prettier is very opinionated and formats HTML in ways I don’t like.

I write Nunjucks templates in HTML mode because VS Code has all sorts of helpers and intellisense for HTML which you lose if you’re in Nunjucks mode.

Thank you I uninstalled my current Nunjucks extension and I guess it no longer formats weirdly.

Too bad there’s no good formatter I can find that works upon save.