Hi, sorry, as I can’t find anywhere else where this question has been asked I know this has to be a real newb question but … please can anyone share the magic of referencing text templates in a subdirectory? It’s driving me crazy!!!
- Take a template tutorial and copy/paste so that the golang source and template are in the same directory
- Build the go source as a Windows .exe and execute.
- Success, it works perfectly and the crowd goes wild - I can successfully copy someone elses work!
- Create a templates subdirectory and copy the template file into it
- Manipulate the source to point to the template in the subdirectory (eg:
dir, _ := filepath.Abs("templates") templateFile := filepath.Join(dir, "email.tmpl") template.ParseFiles(templateFile)
- Compile and execute …
- Scream as you’re told that the template is an “incomplete or empty template”
I’ve tried this every way I can think of but am consistently failing unless I leave the template in the same directory. Please can you put me out of my misery?