Jetbrains Goland HTML模板格式和代码完成 [英] Jetbrains Goland HTML Templates Formatting and Code Completion

查看:175
本文介绍了Jetbrains Goland HTML模板格式和代码完成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Jetbrains Goland中使用Go HTML模板.如何获得全部3:HTML格式,模板代码完成和模板的模板格式?

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?

假设我安装了Go Templates插件,并且正在使用"* .tpl"作为模板的文件扩展名,我有两个选择:

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

  1. 设置-编辑器-文件类型-HTML-添加"* .tpl"作为HTML类型.优点:我有一个HTML代码完成功能和一个语法警告突出显示的语法(请参阅CON 2)缺点1:我没有模板项目的代码完成,编辑器根本不知道模板缺点2:模板代码块被视为文本,即,例如,当我尝试格式化代码时,我没有RANGE块的代码缩进.

  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.

设置-编辑器-文件类型-转到模板-添加"* .tpl"作为带有"HTML"的注册类型作为基础类型(模板数据语言")优点:我已经完成了点"的代码,可以看到它们的属性和方法(请参见 https://www.jetbrains.com/help/go/integration-with-go-templates.html )缺点:没有HTML高亮显示,自动完成或格式化...

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

推荐答案

经过数小时的研究,我终于找到了答案:

After hours of research, I finally found the answer:

设置-语言和框架-模板数据语言-项目语言-设置"HTML"

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

此外,我建议使用"* .go.html"作为Go Templates扩展.这样,即使在VSCode中打开模板,在GitHub上在线等,您也可以看到语法突出显示.

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.

这篇关于Jetbrains Goland HTML模板格式和代码完成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆