I am working on a template that is powered by Go's html/template
package, and I have a specific string value that is passed into the template that needs to be unescaped. The one constraint is that I cannot render the entire template through text/template
, it must be rendered through html/template
.
I have a simplified example of the problem here:
package main
import (
"log"
"os"
"html/template"
)
func main() {
templateStr := `<input type="text" data-thing="{{.dataThing}}"/>`
tmpl, err := template.New("").Parse(templateStr)
if err != nil {
log.Fatal(err)
return
}
tmpl.Execute(os.Stdout, map[string]string{"dataThing":"this->shouldNotEscape"})
}
The current output of the template is: <input type="text" data-thing="this->shouldNotEscape"/>
.
But the desired output of the template is: <input type="text" data-thing="this->shouldNotEscape"/>
.
I have a runnable Go Playground here.