Does Hugo now support templates with the .gohtml extension?

Hello,
I’ve done some research online and found a few threads from one or two years ago where people were asking about Hugo supporting the .gohtml extension for templates. The reason behind this request seemed to be that some editors and software tools recognize .gohtml more easily for syntax highlighting. However, I couldn’t find a definitive answer about whether Hugo has added support for the .gohtml extension over time. I experimented by renaming my _defaults/baseof.html file to _defaults/baseof.gohtml, and it seems to be working fine. However, I was wondering, is this extension officially supported by Hugo now, and would it be safe for me to use it from a future standpoint?

I’m not sure what you mean by … working fine.

Hugo’s template lookup currently considers language, output format and media type … and if you have a output format named gohtml the above would work, but I assume you don’t want that.

That said, I’m using prettier do do code formatting and have a .prettierrc that looks like:

{
  "plugins": [
    "prettier-plugin-go-template"
  ],
  "overrides": [
    {
      "files": [
        "*.html"
      ],
      "options": {
        "parser": "go-template",
        "goTemplateBracketSpacing": true,
        "bracketSameLine": true
      }
    },
    {
      "files": [
        "*.js",
        "*.ts"
      ],
      "options": {
        "useTabs": true,
        "printWidth": 120,
        "singleQuote": true
      }
    }
  ]
}

Which works great for *.html files in VS code.

1 Like

I can add a related tip here: Prettier searches up the file tree for the config file, so if you have lots of Hugo projects below (and don’t want to have one config per project …), put the config file somewhere above. I have mine in:

 /Users/bep/dev/.prettierrc
1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.