- Add function RenderNamedTemplate executes a named template from the registered set with the given data and returns the rendered HTML.

- gormlogger.Silent is the log level that suppresses all Gorm log messages, including the "record not found" warnings.
This commit is contained in:
Zeni Kim 2026-05-11 20:17:30 -05:00
parent 59eadf29d0
commit 19dba8f504
2 changed files with 32 additions and 4 deletions

View file

@ -359,4 +359,22 @@ func NewTemplates(components embed.FS, templates embed.FS) {
ParseFS(components, paths...),
)
tmpl = template.Must(tmpl.ParseFS(templates, pathst...))
}
}
// RenderNamedTemplate executes a named template from the registered set with
// the given data and returns the rendered HTML.
// Usage:
//
// html, err := core.RenderNamedTemplate("tabler_table", data)
// if err != nil {
// // handle error
// }
// return c.Response.HTML(string(html))
func RenderNamedTemplate(name string, data interface{}) (template.HTML, error) {
var buf strings.Builder
if err := tmpl.ExecuteTemplate(&buf, name, data); err != nil {
return "", fmt.Errorf("failed to execute template %q: %w", name, err)
}
return template.HTML(buf.String()), nil
}