
Security News
ECMAScript 2025 Finalized with Iterator Helpers, Set Methods, RegExp.escape, and More
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
github.com/davars/sprig
The Go language comes with a built-in template language, but not very many template functions. This library provides a group of commonly used template functions.
It is inspired by the template functions found in Twig and also in various JavaScript libraries, such as underscore.js.
Template developers can read the Sprig function documentation to learn about the >100 template functions available.
For Go developers wishing to include Sprig as a library in their programs, API documentation is available at GoDoc.org, but read on for standard usage.
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).
Example:
{{ "hello!" | upper | repeat 5 }}
Produces:
HELLO!HELLO!HELLO!HELLO!HELLO!
The following principles were used in deciding on which functions to add, and determining how to implement them.
FAQs
Unknown package
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
ECMAScript 2025 introduces Iterator Helpers, Set methods, JSON modules, and more in its latest spec update approved by Ecma in June 2025.
Security News
A new Node.js homepage button linking to paid support for EOL versions has sparked a heated discussion among contributors and the wider community.
Research
North Korean threat actors linked to the Contagious Interview campaign return with 35 new malicious npm packages using a stealthy multi-stage malware loader.