首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >[Go] template显示html不要被转码

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

作者头像
唯一Chat
发布于 2020-05-26 23:34:57
发布于 2020-05-26 23:34:57
3.1K0
举报
文章被收录于专栏:陶士涵的菜地陶士涵的菜地

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

代码语言:javascript
复制
    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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020-05-23 ,如有侵权请联系 cloudcommunity@tencent.com 删除
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档