Similarly, you should write any other filter. Here is an example that should run you:
from jinja2 import Environment, Undefined def custom_sort(iterable, somearg): if iterable is None or isinstance(iterable, Undefined): return iterable
Do not worry about efficiency until it becomes a problem. In any case, the pattern mechanism is unlikely to be a bottleneck.
Cameron
source share