I found almost nothing on how to format Go templates so here's a quick guide.
- Create your templates, I'm using the
<name>.<type>.html
notation, the<type>
is one of page, layout or partial - Ensure
prettier
is installed globally as well as a plugin to make prettier work with Go templates
npm i -g prettier prettier-plugin-go-template
- Add this
.prettierrc
to the root of your project
{
"overrides": [
{
"files": ["*.html"],
"options": {
"parser": "go-template"
}
}
]
}
- Run the prettier write command whenever you want to format your templates
prettier -w .
the .
represents the current directory