英文:
How to import the HTML type?
问题
html/template
文档中提到了一个HTML
类型:
> HTML、JS、URL和其他来自content.go的类型可以携带安全内容,免于转义。
我该如何导入和使用它?
我尝试了以下代码,但会抛出一个"undefined: HTML"错误(Go Playground):
package main
import (
"fmt"
"html/template"
)
func main() {
fmt.Println(HTML(`<strong>Hi</strong>`))
}
英文:
The html/template
documentation mentions an HTML
type:
> Types HTML, JS, URL, and others from content.go can carry safe content
> that is exempted from escaping.
How can I import and use it?
I have tried the following code, which throws an "undefined: HTML" error (Go Playground):
package main
import (
"fmt"
"html/template"
)
func main() {
fmt.Println(HTML(`<strong>Hi</strong>`))
}
答案1
得分: 1
将类型与包名进行作用域限定:
package main
import (
"fmt"
"html/template"
)
func main() {
fmt.Println(template.HTML(`<strong>Hi</strong>`))
}
英文:
Scope the types with the package name:
package main
import (
"fmt"
"html/template"
)
func main() {
fmt.Println(template.HTML(`<strong>Hi</strong>`))
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论