I'm thinking about creating syntax highlighter for it, but I don't know the conventional abbreviation for this specific type of template.
-
6There isn't one. You can name the file whatever you want. People may often use .tmpl, or even .html, but there's nothing enforcing that, and I often don't use extensions at all.Mr_Pink– Mr_Pink2014-03-07 15:27:01 +00:00Commented Mar 7, 2014 at 15:27
-
I think there are already some syntax highlighters for vim. maybe you can use those as a base for the template filename.Jerry Saravia– Jerry Saravia2014-03-07 17:05:46 +00:00Commented Mar 7, 2014 at 17:05
9 Answers
In one of the examples from the text/template godoc, they refer to ".tmpl" files.
2 Comments
*.html.tmpl has worked well for me in vim/neovim.If you're using the Atom editor with the go-plus plugin, it provides nice syntax highlighting if you use the .gohtml extension.
3 Comments
.go.tmpl, .json.tmpl, .html.tmpl, .yaml.tmpl and so on. Your templating code ideally should not have to care what the intended filetype of the template is.ext.tmpl is probably the least bad option based on my analysis of stats from one large codebase that includes quite a bit of Go code.
Proportion of files with one of the extensions (.tpl, .tmpl, .html.tmpl, .html.tpl, .thtml) that contain the pattern /[{][{](-\ )?end/.
.thtml 0%
.gohtml < 1%
.tpl 14%
.tmpl 85%
This misses simpler go templates that do not use loops or conditionals, but not in a way that should skew results.
About a third of the .tmpl files have the form .ext.tmpl of which .html.tmpl is the single most common. A visual inspection of files sampled from within this show that the extension is an accurate description of the output of the file.
Neither the suffix .tpl nor .tmpl is used exclusively for Go templates within this codebase which has a lot of code that predates the Go language. I haven't investigated carefully, but I think it's safe to say that for each of (.tpl, .tmpl), the majority of files with that extension are probably not Go templates.
3 Comments
In VSCode syntax highlighting of templates could be activated for files with extensions:
.gohtmlor.go.html.gotmplor.go.tmpl
Comments
In jetbrains/goland, you can download the plugin: Go Template
which use .gohtml as default.
Comments
For Neovim:
Using lsp-config, we can trigger gopls on files with custom extensions.
gopls (Go's language server) seems to do a good job with Go's template syntax.
To match VSCode, we can use .gohtml, gotmpl, .go.html and .go.tmpl.
"neovim/nvim-lspconfig"
config = function()
local servers = {
gopls = {
filetypes = { "go", "gomod", "gowork", "gohtml", "gotmpl", "go.html", "go.tmpl" },
},
},
end