Skip to content

A simple library helping you with your Go templates composition

License

Notifications You must be signed in to change notification settings

josuebrunel/templatesmap

Repository files navigation

test coverage goreportcard gopkg license

TemplatesMap

Overview

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.

Installation

To install the templatesmap package, you can simply import it in your Go project:

import "github.com/josuebrunel/templatesmap"

Usage

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.

About

A simple library helping you with your Go templates composition

Resources

License

Stars

Watchers

Forks

Packages

No packages published