如何防止转义'到'html 模板:
package main
import (
"html/template"
"os"
)
const tmpl = `<html>
<head>
<title>{{.Title}}</title>
</head>
</html>`
func main() {
t := template.Must(template.New("ex").Parse(tmpl))
v := map[string]interface{}{
"Title": template.HTML("Hello World'"),
}
t.Execute(os.Stdout, v)
}
它输出:
<html>
<head>
<title>Hello World'</title>
</head>
</html>
期望的输出:
<html>
<head>
<title>Hello World'</title>
</head>
</html>
交互式爱情
相关分类