zl程序教程

您现在的位置是:首页 >  其他

当前栏目

[Go] template显示html不要被转码

2023-02-18 15:41:53 时间

如果直接分配到模板中html的字符串 , 会被转码 , 需要强制把字符串转换成template.HTML类型 , 例如下面这样:

    header := tools.FileGetContent("html/header.html")
    html := tools.FileGetContent("html/list.html")
    t, _ := template.New("list").Parse(html)
    render.(*tools.IndexData).Header=template.HTML(header)
    t.Execute(w, render)
IndexData结构体的 Header属性是  template.HTML类型的
template.HTML