Skip to content

Commit

Permalink
Update README.
Browse files Browse the repository at this point in the history
  • Loading branch information
leekchan committed Jul 14, 2015
1 parent 2689b3b commit 41aaf5f
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

gtf is a useful set of Golang Template Functions. The goal of this project is implementing all built-in template filters of Django & Jinja2.

## Basic Example
## Basic usages

### Method 1 : Uses gtf.New

gtf.New is a wrapper function of [template.New](http://golang.org/pkg/text/template/#New). It automatically adds the gtf functions to the template's function map and returns [template.Template](http://golang.org/pkg/text/template/#Template).

```Go
package main
Expand All @@ -23,6 +27,28 @@ func main() {
}
```

### Method 2 : Adds gtf functions to the exsisting template.

You can also add the gtf functions to the exsisting template. Just call ".Funcs(gtf.GtfFuncMap)".

```Go
package main

import (
"net/http"
"html/template"
"github.com/leekchan/gtf"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tpl, _ := template.New("test").Funcs(gtf.GtfFuncMap).Parse("{{ \"The Go Programming Language\" | stringReplace \" \" }}")
tpl.Execute(w, "")
})
http.ListenAndServe(":8080", nil)
}
```

## Reference
### stringReplace

Expand Down

0 comments on commit 41aaf5f

Please sign in to comment.