quicktemplate
quicktemplate copied to clipboard
Disable HTML escaping
I really like QTPL but I rarely use it for HTML generation but rather go code generation. So I often write code like this to avoid the automatic HTML escaping which is really inconvenient:
func writeunesc(iow io.Writer, s string) {
qw := qt.AcquireWriter(iow)
streamunesc(qw, s)
qt.ReleaseWriter(qw)
}
func unesc(s string) string {
qb := qt.AcquireByteBuffer()
writeunesc(qb, s)
qs := string(qb.B)
qt.ReleaseByteBuffer(qb)
return qs
}
func streamunesc(qw *qt.Writer, s string) {
qw.N().S(s)
}
to use it like this:
{% func Foo(param *ParamType) %}
Some
{%= unesc(param.Text) %}
stuff
{% endfunc %}
So I wanted to ask if there is already a way to deal with this and if not how one could implement this maybe as some thing like {%r param.Text %}
You can already do it with {%s= params.Text %}
.
However, I think it would be interesting to be able to disable escaping for a block of code.