![]() |
hace 2 años | |
---|---|---|
.. | ||
.gitignore | hace 2 años | |
.travis.yml | hace 2 años | |
CHANGELOG.md | hace 2 años | |
LICENSE.txt | hace 2 años | |
Makefile | hace 2 años | |
README.md | hace 2 años | |
appveyor.yml | hace 2 años | |
crypto.go | hace 2 años | |
date.go | hace 2 años | |
defaults.go | hace 2 años | |
dict.go | hace 2 años | |
doc.go | hace 2 años | |
functions.go | hace 2 años | |
glide.yaml | hace 2 años | |
list.go | hace 2 años | |
network.go | hace 2 años | |
numeric.go | hace 2 años | |
reflect.go | hace 2 años | |
regex.go | hace 2 años | |
semver.go | hace 2 años | |
strings.go | hace 2 años | |
url.go | hace 2 años |
The Go language comes with a built-in template language, but not very many template functions. Sprig is a library that provides more than 100 commonly used template functions.
It is inspired by the template functions found in Twig and in various JavaScript libraries, such as underscore.js.
Template developers: Please use Sprig's function documentation for detailed instructions and code snippets for the >100 template functions available.
Go developers: If you'd like to include Sprig as a library in your program, our API documentation is available at GoDoc.org.
For standard usage, read on.
To load the Sprig FuncMap
:
import (
"github.com/Masterminds/sprig"
"html/template"
)
// This example illustrates that the FuncMap *must* be set before the
// templates themselves are loaded.
tpl := template.Must(
template.New("base").Funcs(sprig.FuncMap()).ParseGlob("*.html")
)
By convention, all functions are lowercase. This seems to follow the Go idiom for template functions (as opposed to template methods, which are TitleCase). For example, this:
{{ "hello!" | upper | repeat 5 }}
produces this:
HELLO!HELLO!HELLO!HELLO!HELLO!
We followed these principles to decide which functions to add and how to implement them: