Go template.ExecuteTemplate include html

后端 未结 8 1991
我在风中等你
我在风中等你 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 11:21

    I'm using Beego and React.js and fought for hours trying to get the JSX parser to run. Turns out html/template strips out comments especially the js doc block /** @jsx React.DOM */.

    Got around it by creating a special method to Type the comment as JS and calling it from within the template.

    // Create a method in your controller (I'm using Beego)
    func jsxdoc()(out template.JS) {
        return template.JS(`/** @jsx React.DOM */`)
    }
    
    // Add method to your function map available to views
    beego.AddFuncMap("jsxdoc", jsxdoc)
    
    // In template
    
    

提交回复
热议问题