fasttemplate alternatives and similar packages
Based on the "Template Engines" category.
Alternatively, view fasttemplate alternatives based on common mentions on social networks and blogs.
-
gofpdf
A PDF document generator with high level support for text, drawing and images. -
quicktemplate
Fast, powerful, yet easy to use template engine for Go. Optimized for speed, zero memory allocations in hot paths. Up to 20x faster than html/template -
maroto
A maroto way to create PDFs. Maroto is inspired in Bootstrap and uses gofpdf. Fast and simple. -
amber
Amber is an elegant templating engine for Go Programming Language, inspired from HAML and Jade -
goview
Goview is a lightweight, minimalist and idiomatic template library based on golang html/template for building Go web application. -
grender
Go package for easily rendering JSON/XML data and HTML templates -
extemplate
Wrapper package for Go's template/html to allow for easy file-based template inheritance. -
kasia.go
Templating system for HTML and other text documents - go implementation -
gospin
Article spinning and spintax/spinning syntax engine written in Go, useful for A/B, testing pieces of text/articles and creating more natural conversations -
damsel
Package damsel provides html outlining via css-selectors and common template functionality. -
tbd
"to be defined" - a really simple way to create text templates with placeholders -
GoT
GoT is a template engine that turns templates into Go code to compile into your app. -
Blip Template Engine for Go
Go Template Engine for type safe / fast rendering Benefits: Very Fast rendering Compile time type checking, Type safe! Template Extending / Including Simple syntax Auto-Escaping Support passing variables directly and via context Extendable escaping / monitoring
Clean code begins in your IDE with SonarLint
Do you think we are missing an alternative of fasttemplate or a related project?
README
fasttemplate
Simple and fast template engine for Go.
Fasttemplate performs only a single task - it substitutes template placeholders with user-defined values. At high speed :)
Take a look at quicktemplate if you need fast yet powerful html template engine.
Please note that fasttemplate doesn't do any escaping on template values unlike html/template do. So values must be properly escaped before passing them to fasttemplate.
Fasttemplate is faster than text/template, strings.Replace, strings.Replacer and fmt.Fprintf on placeholders' substitution.
Below are benchmark results comparing fasttemplate performance to text/template, strings.Replace, strings.Replacer and fmt.Fprintf:
$ go test -bench=. -benchmem
PASS
BenchmarkFmtFprintf-4 2000000 790 ns/op 0 B/op 0 allocs/op
BenchmarkStringsReplace-4 500000 3474 ns/op 2112 B/op 14 allocs/op
BenchmarkStringsReplacer-4 500000 2657 ns/op 2256 B/op 23 allocs/op
BenchmarkTextTemplate-4 500000 3333 ns/op 336 B/op 19 allocs/op
BenchmarkFastTemplateExecuteFunc-4 5000000 349 ns/op 0 B/op 0 allocs/op
BenchmarkFastTemplateExecute-4 3000000 383 ns/op 0 B/op 0 allocs/op
BenchmarkFastTemplateExecuteFuncString-4 3000000 549 ns/op 144 B/op 1 allocs/op
BenchmarkFastTemplateExecuteString-4 3000000 572 ns/op 144 B/op 1 allocs/op
BenchmarkFastTemplateExecuteTagFunc-4 2000000 743 ns/op 144 B/op 3 allocs/op
Docs
See http://godoc.org/github.com/valyala/fasttemplate .
Usage
template := "http://{{host}}/?q={{query}}&foo={{bar}}{{bar}}"
t := fasttemplate.New(template, "{{", "}}")
s := t.ExecuteString(map[string]interface{}{
"host": "google.com",
"query": url.QueryEscape("hello=world"),
"bar": "foobar",
})
fmt.Printf("%s", s)
// Output:
// http://google.com/?q=hello%3Dworld&foo=foobarfoobar
Advanced usage
template := "Hello, [user]! You won [prize]!!! [foobar]"
t, err := fasttemplate.NewTemplate(template, "[", "]")
if err != nil {
log.Fatalf("unexpected error when parsing template: %s", err)
}
s := t.ExecuteFuncString(func(w io.Writer, tag string) (int, error) {
switch tag {
case "user":
return w.Write([]byte("John"))
case "prize":
return w.Write([]byte("$100500"))
default:
return w.Write([]byte(fmt.Sprintf("[unknown tag %q]", tag)))
}
})
fmt.Printf("%s", s)
// Output:
// Hello, John! You won $100500!!! [unknown tag "foobar"]