将您的
[]byte或转换
string为类型
template.HTML(在此处记录)
p.Body = template.HTML(s) // where s is a string or []byte
然后,在您的模板中,只需:
{{.Body}}它将被打印而不会逃脱。
编辑
为了能够在页面正文中包含HTML,您需要更改
Page类型声明:
type Page struct { Title string Body template.HTML}然后分配给它。

将您的
[]byte或转换
string为类型
template.HTML(在此处记录)
p.Body = template.HTML(s) // where s is a string or []byte
然后,在您的模板中,只需:
{{.Body}}它将被打印而不会逃脱。
编辑
为了能够在页面正文中包含HTML,您需要更改
Page类型声明:
type Page struct { Title string Body template.HTML}然后分配给它。