what's the proper file extension or abbr. for golang's text/template?

a 夏天 提交于 2019-12-04 22:36:17

In one of the examples from the text/template godoc, they refer to ".tmpl" files.

If you're using the Atom editor with the go-plus plugin, it provides nice syntax highlighting if you use the .gohtml extension.

.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.

I'm using .html.tmpl. That makes it clear that it's a Go template which will be rendered to HTML. Furthermore, it follows the convention set by other file types like .tar.gz.

The html/template package uses .tmpl in their example.
My vote goes to .html.tmpl

Since you're writing the highlighter just go with what you normally use. I'm sure the community will give you feedback and eventually some sort of agreement.

As for myself, I'm using .thtml for template html.

In VSCode syntax highlighting of templates could be activated for files with extensions:

  • .gohtml or .go.html
  • .gotmpl or .go.tmpl

https://github.com/microsoft/vscode-go/issues/464

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!