码迷,mamicode.com
首页 > Web开发 > 详细

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

时间:2020-05-23 18:29:46      阅读:65      评论:0      收藏:0      [点我收藏+]

标签:字符串转换   get   转换   结构体   end   显示   code   file   结构   

如果直接分配到模板中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

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

标签:字符串转换   get   转换   结构体   end   显示   code   file   结构   

原文地址:https://www.cnblogs.com/taoshihan/p/12943549.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!