pongo2filters

package module
v1.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 23, 2026 License: MIT Imports: 12 Imported by: 0

README

Pongo2 Filters

This repository implements a number of additional filters for the excellent pongo2 template engine. Note that as most of these filters are inspired by Jinja2 template syntax, this module requires my fork of pongo2 which implements several Jinja2 syntax features.

Filters List

Jinja2-compatible

  • abs - Returns the absolute value of the argument. (doc)

  • attr - Get an attribute of an object. (doc)

  • batch - A filter that batches items. (doc)

  • capitalize - Capitalize a value. (doc)

  • format - Apply the given values to a printf-style format string, like string % values. (doc)

  • indent - Return a copy of the string with each line indented by 4 spaces. (doc)

  • int - Convert the value into an integer. (doc)

  • list - Convert the value into a list. (doc)

  • map - Applies a filter on a sequence of objects or looks up an attribute. (doc)

  • max - Return the largest item from the sequence. (doc)

  • min - Return the smallest item from the sequence. (doc)

  • pprint - Pretty print a variable. (doc)

  • reject - Filters a sequence of objects by applying a test to each object, and rejecting the objects with the test succeeding. (doc)

  • rejectattr - Filters a sequence of objects by applying a test to the specified attribute of each object, and rejecting the objects with the test succeeding. (doc)

  • replace - Return a copy of the value with all occurrences of a substring replaced with a new one. (doc)

  • reverse - Reverse the object or return an iterator that iterates over it the other way round. (doc)

  • round - Round the number to a given precision. (doc)

  • select - Filters a sequence of objects by applying a test to each object, and only selecting the objects with the test succeeding. (doc)

  • selectattr - Filters a sequence of objects by applying a test to the specified attribute of each object, and only selecting the objects with the test succeeding. (doc)

  • sort - Sort an iterable. (doc)

  • string - Convert an object to a string if it isn’t already. (doc)

  • sum - Returns the sum of a sequence of numbers plus the value of parameter ‘start’ (which defaults to 0). (doc)

  • tojson - Serialize an object to a string of JSON, and mark it safe to render in HTML. (doc)

  • trim - Strip leading and trailing characters, by default whitespace. (doc)

  • truncate - Return a truncated copy of the string. (doc)

  • unique - Returns a list of unique items from the given iterable. (doc)

  • xmlattr - Create an SGML/XML attribute string based on the items in a dict. (doc)

Ansible-compatible

  • extract - Extract a value based on an index or key. (doc)

  • quote - Shell quoting. (doc)

  • regex_replace - Replace a string via regex. (doc)

Additional custom filters

  • sprintf - Like format (from the Jinja2-compatible filters list above) but the first argument is the format string and the variable is the value to be formatted.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrIterable = errors.New("input value is not iterable")

Functions

func AddJinja2

func AddJinja2(t *pongo2.TemplateSet) error

Types

type JSONEncodeFunc

type JSONEncodeFunc func(v interface{}, indent int) ([]byte, error)
var JSONEncoder JSONEncodeFunc = stdJSONEncoder

JSONEncoder specifies a callback to use to encode JSON values as an alternative to the (ridiculously slow) standard library encoder. This should be set before the first template is created and not modified again.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL