8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

GO Template Engineでhtmlをエスケープしないで表示する

Posted at

stringまたは[]bytetemplate.HTMLに変換することによって、GO Template Engine側でhtmlのエスケープ処理が走らなくなる。

Revelで使用する際のサンプル

app.go
func (c *revel.Controller) Show() revel.Result {
	escape_html := "<h1>Hello World</h1>"
	raw_html    := template.HTML(escape_html)
	return c.Render(escape_html, raw_html)
}
show.html
{{escape_html}}  <!-- &lt;h1&gt;Hello World&lt;/h1&gt; -->
{{raw_html}}     <!-- <h1>Hello World</h1> -->
8
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?