Html template parse with sprig does not work in go

309 Views Asked by At

I am very new to golang and trying to use sprig package with html/template. I am converting the template to PDF. I get a blank response in postman when I use the below code(parseFiles). tempPath variable is just a string with the path to my html template.

tmpl := htmlTemplate.Must(htmlTemplate.New("test").Funcs(sprig.FuncMap()).ParseFiles(tempPath))

and with below code(parse) it just prints the file path to the pdf which I can see in postman

tmpl := htmlTemplate.Must(htmlTemplate.New("test").Funcs(sprig.FuncMap()).Parse(tempPath))

The PDF gets perfectly converted from html to PDF without using the sprig package with the below code(parseFiles)

tmpl, err := htmlTemplate.ParseFiles(tempPath)

Any idea what I am doing wrong? Please help.

0

There are 0 best solutions below