1

我需要将字符串呈现为 html 中的Revel. 这个怎么做?我试过了:

func (c Pages) Show(url string) revel.Result {    
    bigDig := "<h1>Hello, dig!</h1>"

    return c.Render(bigDig)
}

然后在view

{{template "header.html" .}}

{{.bigDig}}

{{template "footer.html" .}}

但它不起作用。这个怎么做?

4

2 回答 2

2

您的 var 必须是 template.HTML 类型。

阅读http://golang.org/pkg/html/template/#HTMLhttps://groups.google.com/forum/#!topic/golang-nuts/8L4eDkr5Q84

于 2014-07-11T12:52:50.330 回答
1

你应该改变你{{.bigDig}}{{raw .bigDig}}

于 2015-12-14T01:12:48.940 回答