An open API service indexing awesome lists of open source software.

https://github.com/lestrrat-go/tmplbox

Yet Another (text|html)/template wrapper
https://github.com/lestrrat-go/tmplbox

Last synced: 4 months ago
JSON representation

Yet Another (text|html)/template wrapper

Awesome Lists containing this project

README

        

# tmplbox

Yet Another (text|html)/template wrapper

[![Build Status](https://travis-ci.org/lestrrat-go/tmplbox.svg?branch=master)](https://travis-ci.org/lestrrat-go/tmplbox)

[![GoDoc](https://godoc.org/github.com/lestrrat-go/tmplbox?status.svg)](https://godoc.org/github.com/lestrrat-go/tmplbox)

# SYNOPSIS

```html

{{ define "root" }}

{{ block "content" }}{{ end }}

{{ end }}
```

```html

{{ define "content" }}Hello, World!{{ end }}
```

```go
// 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
//
//
//
// Hello, World!
//
//
t.ExecuteTemplate(w, "root", nil)
}
```

# FEATURES

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