代码如下
```
package main
import (
"html/template"
"log"
"os"
)
func main() {
const templateText = `
{{.name}}
`
tmpl, err := template.New("").Parse(templateText)
if err != nil {
log.Fatalf("parsing: %s", err)
}
var name= `测试"引号"`
err = tmpl.Execute(os.Stdout, map[string]string{"name":name})
if err != nil {
log.Fatalf("execution: %s", err)
}
}
```
输出:
![1.jpg](https://static.studygolang.com/180425/ca78c3a0bcad3020efa375a5781d9af2.jpg)
我想保留引号,请问怎么防止转义
测试`tmpl.Execute(os.Stdout, map[string]interface{}{"name":template.HTML(name)})`成功, :smile:
#2
更多评论