Go template.ExecuteTemplate include html

后端 未结 8 1975
我在风中等你
我在风中等你 2020-12-01 10:19

I have followed this tutorial: http://golang.org/doc/articles/wiki/final.go and have slightly modified it for my needs/wants. The problem is I would like to support HTML in

8条回答
  •  借酒劲吻你
    2020-12-01 10:57

    I created a custom function for the template as follows:

    func noescape(str string) template.HTML {
        return template.HTML(str)
    }
    
    var fn = template.FuncMap{
        "noescape": noescape,
    }
    

    Then on your template:

    {{ noescape $x.Body }}
    

提交回复
热议问题