Helper functions for use in Genshi templates

Often you need non-trivial presentation logic in templates, but Genshi does not (yet) let you drop into straight Python. In Genshi, such presentation logic must be either performed in the controller (i.e. the Python code feeding the template with date), or in helper functions that are called from within template expressions.

This page serves as a place where generalized functions that solve common tasks in presentation logic can be collected. At some point, Genshi might include a library of such functions.

Python Standard Library

Many of the Python ​builtin functions (such as reversed or sorted), as well as those in the ​itertools package (such as groupby), can be quite useful in templates. The builtin functions are available by default, whereas other functions need to be put in the template context data explicitly.