<p>EDIT: can't edit the title, but it was supposed to be "how to not autoescape html in templates"</p>
<p>I am using html/template for my webapp which uses a lib for doing html conversion from markdown, when I use html/template, the rendered template doesn't render the html, it injects an auto escaped html! (Earlier, by IDE auto imports, I was foolishly using text/template so this problem did not arise.)</p>
<hr/>**评论:**<br/><br/>thewhitetulip: <pre><p>Found the solution:</p>
<pre><code>vars := map[string] interface {} {
"Title":"Test",
"Body":template.HTML("Hello <b>World</b>"),
}
</code></pre>
<p>If we make the thing as not string but template.HTML, then we are good to go.</p>
<p><a href="http://play.golang.org/p/Uw8l3M7Qvg" rel="nofollow">http://play.golang.org/p/Uw8l3M7Qvg</a></p></pre>neoasterisk: <pre><p>You could consider using a <code>struct</code> instead of a <code>map[string]interface{}</code>.</p></pre>thewhitetulip: <pre><p>Indeed, <a href="https://github.com/thewhitetulip/Tasks/blob/master/types/types.go#L14" rel="nofollow">https://github.com/thewhitetulip/Tasks/blob/master/types/types.go#L14</a></p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传