I could not find iris support for sharing html un-esccaped string with ctx
Currently, I had to hack code to print output in HTML :-
go file :-
ctx.ViewData("content", "<p>This is HTML content.</p><br><h3>Another String</h3>")
template file.
<script>
document.write(unescape({{ .content }}))
</script>
But, I am looking for simple way to print data without unescape in javascript
@krokite I don't know if this is the best way, but this is how I do it and it works:
```go
ctx.ViewData("content", template.HTML("
This is HTML content.
or create a tmpl func:
```go
tmpl := iris.HTML(...)
tmpl.AddFunc("html", func(text string) template.HTML {
return template.HTML(text)
})
ctx.ViewData("text", "<p>This is HTML content.</p><br><h3>Another String</h3>")
{{html .text}}
Don't forget to import the "html/template" package.
@krokite and @speedwheel correct, this is the right way, this is the go way. If you use the iris.HTML view engine, which is an improvement version of the html/template, you should the template.HTML to bind a "secure" html string to the view template, this is the reason that _examples folder says that you should learn how net/http works before starting with Iris, although it's easy, 2-3 days and you're ready to GO but you have to do that step.
Most helpful comment
@krokite and @speedwheel correct, this is the right way, this is the go way. If you use the
iris.HTMLview engine, which is an improvement version of thehtml/template, you should thetemplate.HTMLto bind a "secure" html string to the view template, this is the reason that _examples folder says that you should learn hownet/httpworks before starting with Iris, although it's easy, 2-3 days and you're ready to GO but you have to do that step.