Search code examples
gogo-templatesgoland

Jetbrains Goland HTML Templates Formatting and Code Completion


I am using Go HTML Templates in Jetbrains Goland. How do I get all 3: HTML formatting, template code completion, and template formatting for templates?

Assuming I installed Go Templates plugin and I am using "*.tpl" as a file extension for my templates, I have two options:

  1. Settings - Editor - Filetypes - HTML - Add "*.tpl" as an HTML type. PROS: I have an HTML code completion and syntax highlighting with a caveat (see CON 2) CON 1: I do not have code completion on template items, the editor is unaware of templates at all CON 2: Template code blocks are treated as text, i.e. I do not have code indentation for RANGE blocks for example when I try to format my code.

  2. Settings - Editor - Filetypes - Go Templates - Add "*.tpl" as registered type with "HTML" as an underlying type ("Template data language") PROS: I have code completion for 'dots' and can see properties and methods on them (see https://www.jetbrains.com/help/go/integration-with-go-templates.html) CONS: No HTML highlighting, autocompletion, or formatting...


Solution

  • After hours of research, I finally found the answer:

    Settings - Languages and Frameworks - Template Data Languages - Project Language - Set "HTML"

    Also, I suggest using "*.go.html" as a Go Templates extension. This way you can see syntax highlighting even when opening the template in VSCode, online on GitHub, etc.