Skip to content

lestrrat-go/tmplbox

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

tmplbox

Yet Another (text|html)/template wrapper

Build Status

GoDoc

SYNOPSIS

<!-- base.html -->
{{ define "root" }}
<html>
<body>
{{ block "content" }}{{ end }}
</body>
</html>
{{ end }}
<!-- index.html -->
{{ define "content" }}Hello, World!{{ end }}
// assuming you're using go-bindata's Asset function to
// retrieve template sources here.
var box := tmplbox.New(tmplbox.AssetSourceFunc(Asset))

func indexHandler(w http.ResponseWriter, r *http.Response) {
    // Assuming you have a dependency between index.html and
    // base.html (see above), GetOrCompose will automatically
    // compile and merge all of the specified templates.
    t, _ := box.GetOrCompose("index.html", "base.html")

    // Will output 
    // <!-- base.html -->
    // <html>
    // <body>
    // Hello, World!
    // </body>
    // </html>
    t.ExecuteTemplate(w, "root", nil)
}

FEATURES

  • Plays well with go-bindata
  • Easy to setup template dependency to emulate "extends", without another big library

About

Yet Another (text|html)/template wrapper

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages