Skip to content

MarioJim/gonja

 
 

Repository files navigation

gonja

gonja is a pure go implementation of the Jinja template engine. It aims to be mostly compatible with the original python implementation but also provides additional features to compensate the lack of python scripting capabilities.

Usage

As a library

Install/update using go get:

go get github.com/MarioJim/gonja

Example

package main

import (
	"fmt"

	"github.com/MarioJim/gonja"
)

func main() {
	tpl, err := gonja.FromString("Hello {{ name | capitalize }}!")
	if err != nil {
		panic(err)
	}
	out, err := tpl.Execute(gonja.Context{"name": "bob"})
	if err != nil {
		panic(err)
	}
	fmt.Println(out) // Prints: Hello Bob!
}

Documentation

Limitations

  • format: format does not take Python's string format syntax as a parameter, instead it takes Go's. Essentially {{ 3.14|stringformat:"pi is %.2f" }} is fmt.Sprintf("pi is %.2f", 3.14).
  • escape / force_escape: Unlike Jinja's behavior, the escape-filter is applied immediately. Therefore there is no need for a force_escape-filter yet.

Tribute

A massive thank you to the original author @noirbizarre for doing the initial work in https://github.com/noirbizarre/gonja which this project was forked from.

About

⛩️ Pure Golang engine for Jinja templates

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 100.0%