The templatesmap
package is a Go library for managing HTML templates. It provides a convenient way to load, store, and render HTML templates with dynamic data. It's particularly useful for web applications needing to serve various HTML pages or layouts.
To install the templatesmap
package, you can simply import it in your Go project:
import "github.com/josuebrunel/templatesmap"
It works with patterns just like template.ParseGlob
.
layoutPath := "templates/layouts/*.html"
userPath := "templates/user/*.html"
rolePath := "templates/role/*.html"
funcs := template.FuncsMap{
"upper": strings.ToUpper,
}
tplMap, err := templatesmap.NewTemplatesMap(layoutPath, funcs, userPath, rolePath)
if err != nil {
log.Fatal(err)
}
tpl.Render(os.Stdout, "user-detail.html", user)
Read the templatesmap_test.go for more.