-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
Hello
I have a problem when i'm using embed structs. Let me explain.
I have this code :
type TemplateReader struct {
filename string
}
func (t TemplateReader) TemplateText() string {
fileContent, err := os.ReadFile(t.filename)
if err != nil {
return "template not found: " + t.filename
}
return string(fileContent)
}
type Layout struct {
Class string
Body Test `tmpl:"body"`
TemplateReader
}
type Test struct {
}
func (*Test) TemplateText() string {
fileContent, err := os.ReadFile("feature/authentication/login/template/login.html")
if err != nil {
return "template not found: login"
}
return string(fileContent)
}
t := &Test{}
body := &Layout{
"main-register",
*t,
TemplateReader{
filename: "template/base.html",
},
}
ta := tmpl.MustCompile(body, compilerOption)
result, err := ta.RenderToString(body)With this code, the template is not found, its output template not found: without the template name.
When i'm calling directly fmt.Printf("%+v\n", body.TemplateText()) the template is found.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels