问题描述
我正在使用由Go的marshal
软件包提供支持的模板,并且我有一个特定的字符串值,该字符串值传递到需要取消转义的模板中。一个约束是我无法通过html/template
渲染整个模板,而必须通过text/template
渲染。
我在这里有问题的简化示例:
html/template
模板的当前输出为:package main
import (
"log"
"os"
"html/template"
)
func main() {
templateStr := `<input type="text" data-thing="{{.dataThing}}"/>`
tmpl,err := template.New("").Parse(templateStr)
if err != nil {
log.Fatal(err)
return
}
tmpl.Execute(os.Stdout,map[string]string{"dataThing":"this->shouldNotEscape"})
}
。
但是模板的期望输出是:<input type="text" data-thing="this->shouldNotEscape"/>
。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)