So i try to put image in from base64 but i'm gettin ZgotmplZ i try to use template.URL(s) like this:
e := echo.New()
funcMap := template.FuncMap{
"safe": func(s string) template.URL {
return template.URL(s)
},
}
t := &Template{
templates: template.Must(template.ParseGlob("C:/Projects/Golang/hello/resources/*.html")).Funcs(funcMap),
}
e.Renderer = t
e.GET("/", func(context echo.Context) error {
return context.Render(http.StatusOK, "index.html", GetData())
})
and in template:
<td rowspan="2"><img src="{{.Icon|safe}}"></td>
But while i exeute: go run panic: template: index.html:34: function "safe" not defined so what i do wrong?
The template functions must be defined before the template is parsed. To fix the error, create an empty template, set the functions and then parse the glob:
templates: template.Must(template.New("").Funcs(funcMap).ParseGlob("C:/Projects/Golang/hello/resources/*.html")),