Hugo: Add support for .tmpl file extension in template lookup order

Created on 24 Mar 2017  ยท  8Comments  ยท  Source: gohugoio/hugo

Primarily driven by the upcoming custom output format feature (#2828).

Rationale:

  • Can't assume that we're dealing with HTML-type formats any longer.
  • Want a predictable filename for editors to do syntax highlighting of template actions ({{ ... }}).

Do we want to drive the potential lookup based upon the Output Format? So, if we have a "JSON" Output Format, we would lookup:

  • index.json
  • index.json.tmpl

This would exclude index.json.html. Lookup would essentially be:

  • {{ .Name }}.{{ .Format }}
  • {{ .Name }}.{{ .Format }}.tmpl

Original discussion: https://discuss.gohugo.io/t/custom-output-formats-feedback-wanted/5886/2

Enhancement

Most helpful comment

In Intellij Idea products *.gohtml is used for Go Templates
Maybe extension should be customizable, so any extensions instead of html can be used.

All 8 comments

Hello,
"Can't assume that we're dealing with HTML-type formats any longer."
But we still assume a text output?
If not, then maybe it is the way to handle images?

Can I kindly ask for contributor's vision of image processing?

Notes:
The only native image processing support: #3158

But we still assume a text output?

yes.

I would like to second predictability in IDE aspect.

For example in PhpStorm there is no way to assign *.html to the Go Template file type (provided by a plugin) without _removing_ it from HTML file type globally across all projects. :\

In Intellij Idea products *.gohtml is used for Go Templates
Maybe extension should be customizable, so any extensions instead of html can be used.

Btw, my current workaround is to have *.gohtml for every layout *.html:

โ”œโ”€โ”€ layouts
โ”‚   โ”œโ”€โ”€ 404.gohtml
โ”‚ย ย  โ”œโ”€โ”€ 404.html
โ”‚ย ย  โ”œโ”€โ”€ home.gohtml
โ”‚ย ย  โ”œโ”€โ”€ home.html

and include *.gohtml from *.html:

home.html

{{ template "home.gohtml" . }}

Another workaround Iโ€™m currently using:

  1. Include the Custom Output Format in the template filename (e.g. single.html.html for HTML output format)
  2. Assign *.html.html as pattern for Go Template file types in the Jetbrains IDE.

Simple *.html files are still being assigned to the HTML file type that way.

While writing a prettier plugin to fix go template support I stumbled upon this. It would be really nice for formatters, if GoHugo would support .tmpl.

+1, this would simplify usage with IntelliJ IDEA-based editors.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

tjamet picture tjamet  ยท  3Comments

moorereason picture moorereason  ยท  3Comments

mumblecrunch picture mumblecrunch  ยท  3Comments

digitalcraftsman picture digitalcraftsman  ยท  3Comments

carandraug picture carandraug  ยท  3Comments