1

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.

girish
  • 302
  • 1
  • 5
  • 17
  • What does the error from Execute/ExecuteTemplate say? Or is it the parsing that fails? if yes, then what does the error from ParseFiles/ParseGlob/Parse say? – mkopriva Mar 31 '23 at 14:02
  • it says `template: "test" is an incomplete or empty template`. I also tried passing the tempPath in place of "test" but still same error. – girish Mar 31 '23 at 14:06
  • It worked for me. for htmlTemplate.New() only file name has to be passed like "test.html" and for .ParseFiles() full path to the template has to be given with file name like "templates/test.html" – girish Mar 31 '23 at 14:55

0 Answers0