Go template.ExecuteTemplate include html

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

    Why not convert the []byte to a string? You can do it like this:

    str := string(page.Body)
    
    0 讨论(0)
  • 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
    <script type="text/jsx">
        {{ jsxdoc }}
        var CommentBox = React.createClass({
          render: function() {
            return (
              <div class="commentBox">
                Hello, world! I am a CommentBox.
              </div>
            );
          }
        });
        React.renderComponent(
          <CommentBox />,
          document.getElementById('content')
        );
    </script>
    
    0 讨论(0)
提交回复
热议问题