Can Hugo be configured to recognize paths that don't end in ".html"?

Most of Hugo’s default paths, like <theme>/layouts/index.html, require the extension .html. Most common IDEs and editors assume that files with an .html extension are HTML and should be syntax-highlighted as such. (For example, this is true for Atom, VS Code, Sublime Text, vim, and emacs.)

However, most of the time, your Hugo files are actually Go HTML templates, meaning that they’re not really HTML, but rather a mix of HTML and Go’s html/template. That means that the Go template fragments won’t be identified correctly, since they aren’t part of HTML. Calling these files HTML seems not quite right, therefore.

Since the name of the template is arbitrary, is it possible to ask Hugo to look for an arbitrarily configurable list of names (rather than the <theme>/layouts/index.html-style ordering), for purposes of identifying a suitable template to use in a given situation? The convention in other languages is to suffix the order of expected processing – e.g., index.html.go if it’s going to be processed by Go and then as HTML.

Currently no.

Has this changed? :sweat_smile:

Most of the named editors are able to change how file endings are parsed and syntax-highlighted. I have no issues on Sublime Edit and PhpStorm to set per-project configurations to read .html as golang templates.

In regards to “it’s a mix of html and golang templates so don’t call them .html” - they might even be a mix of html, golang, css and javascript too, so what should we call them then? Let the editor be the solution to this. I am 100% sure, that Atom, VSCode can solve that via plugins and project settings. Vim and emacs probably too, but all my grandparents are dead, so I have nobody who uses them, hehe… hehehehe… sorry.

All following links untested, I used Google for you:

And I remember pretty recently a post about sublime text here in discourse about per-project settings for go templates.

1 Like