All Projects β†’ Masterminds β†’ Sprig

Masterminds / Sprig

Licence: mit
Useful template functions for Go templates.

Programming Languages

go
31211 projects - #10 most used programming language
Makefile
30231 projects

Projects that are alternatives of or similar to Sprig

Cgx
πŸ’»πŸ”₯CLI to generate the recommended documentation/files to improve contribution (Github, Gitlab, CodeCommit and Bitbucket)
Stars: ✭ 190 (-92.97%)
Mutual labels:  templates, template
Tufte Latex
A Tufte-inspired LaTeX class for producing handouts, papers, and books
Stars: ✭ 1,161 (-57.02%)
Mutual labels:  templates, template
Freemo
A free resume,portfolio and CV HTML template
Stars: ✭ 30 (-98.89%)
Mutual labels:  templates, template
Mikado
Mikado is the webs fastest template library for building user interfaces.
Stars: ✭ 323 (-88.04%)
Mutual labels:  templates, template
Kotlin Gradle Plugin Template
🐘 A template to let you started with custom Gradle Plugins + Kotlin in a few seconds
Stars: ✭ 141 (-94.78%)
Mutual labels:  templates, template
Vim Template
Simple templates plugin for Vim
Stars: ✭ 328 (-87.86%)
Mutual labels:  templates, template
Wedding Website
Our Wedding Website πŸ‘«
Stars: ✭ 1,090 (-59.64%)
Mutual labels:  templates, template
Tail Kit
Tail-kit is a free and open source components and templates kit fully coded with Tailwind css 2.0.
Stars: ✭ 997 (-63.09%)
Mutual labels:  templates, template
Open React Template
A free React landing page template designed to showcase open source projects, SaaS products, online services, and more. Made by
Stars: ✭ 1,956 (-27.58%)
Mutual labels:  templates, template
Seven
Eleventy template using Bootstrap, Sass, Webpack, Vue.js powered search, includes lots of other features
Stars: ✭ 114 (-95.78%)
Mutual labels:  templates, template
Email Templates
πŸ“« Create, preview, and send custom email templates for Node.js. Highly configurable and supports automatic inline CSS, stylesheets, embedded images and fonts, and much more!
Stars: ✭ 3,291 (+21.84%)
Mutual labels:  templates, template
Pongo2
Django-syntax like template-engine for Go
Stars: ✭ 2,111 (-21.84%)
Mutual labels:  templates, template
Jade
Jade.go - pug template engine for Go (golang)
Stars: ✭ 251 (-90.71%)
Mutual labels:  templates, template
Ant Design Landing
🚡 Landing Pages of Ant Design System
Stars: ✭ 4,425 (+63.83%)
Mutual labels:  templates, template
Github Issue Templates
πŸ”£ A collection of GitHub issue and pull request templates
Stars: ✭ 3,074 (+13.81%)
Mutual labels:  templates, template
Staradmin Free Bootstrap Admin Template
A Free Responsive Admin Dashboard Template Built With Bootstrap 4. Elegant UI Theme for Your Web App!
Stars: ✭ 1,191 (-55.91%)
Mutual labels:  templates, template
Latex Koma Template
Generic template for midsize and larger documents based on KOMA script classes.
Stars: ✭ 151 (-94.41%)
Mutual labels:  templates, template
Ng Polymorpheus
Polymorpheus is a tiny library for polymorphic templates in Angular.
Stars: ✭ 191 (-92.93%)
Mutual labels:  templates, template
Vuepress Homepage
πŸ“„ Elegant & friendly homepage (bio, tech portfolio, resume, doc...) template with Markdown and VuePress
Stars: ✭ 186 (-93.11%)
Mutual labels:  template
Pandoc Markdown Book Template
A template for creating epub books from markdown using pandoc.
Stars: ✭ 191 (-92.93%)
Mutual labels:  template

Sprig: Template functions for Go templates

GoDoc Go Report Card Stability: Sustained

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.

IMPORTANT NOTES

Sprig leverages mergo to handle merges. In its v0.3.9 release, there was a behavior change that impacts merging template functions in sprig. It is currently recommended to use v0.3.10 or later of that package. Using v0.3.9 will cause sprig tests to fail.

Package Versions

There are two active major versions of the sprig package.

  • v3 is currently stable release series on the master branch. The Go API should remain compatible with v2, the current stable version. Behavior change behind some functions is the reason for the new major version.
  • v2 is the previous stable release series. It has been more than three years since the initial release of v2. You can read the documentation and see the code on the release-2 branch. Bug fixes to this major version will continue for some time.

Usage

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.

Load the Sprig library

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")
)

Calling the functions inside of templates

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!

Principles Driving Our Function Selection

We followed these principles to decide which functions to add and how to implement them:

  • Use template functions to build layout. The following types of operations are within the domain of template functions:
    • Formatting
    • Layout
    • Simple type conversions
    • Utilities that assist in handling common formatting and layout needs (e.g. arithmetic)
  • Template functions should not return errors unless there is no way to print a sensible value. For example, converting a string to an integer should not produce an error if conversion fails. Instead, it should display a default value.
  • Simple math is necessary for grid layouts, pagers, and so on. Complex math (anything other than arithmetic) should be done outside of templates.
  • Template functions only deal with the data passed into them. They never retrieve data from a source.
  • Finally, do not override core Go template functions.
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].