![]() |
2 éve | |
---|---|---|
.. | ||
.gitignore | 2 éve | |
.travis.yml | 2 éve | |
CHANGELOG.md | 2 éve | |
LICENSE.txt | 2 éve | |
Makefile | 2 éve | |
README.md | 2 éve | |
appveyor.yml | 2 éve | |
crypto.go | 2 éve | |
date.go | 2 éve | |
defaults.go | 2 éve | |
dict.go | 2 éve | |
doc.go | 2 éve | |
functions.go | 2 éve | |
glide.yaml | 2 éve | |
list.go | 2 éve | |
network.go | 2 éve | |
numeric.go | 2 éve | |
reflect.go | 2 éve | |
regex.go | 2 éve | |
semver.go | 2 éve | |
strings.go | 2 éve | |
url.go | 2 éve |
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: