Ibis

A template engine for people who enjoy the simpler things in life.

Version 3.3.0

Filter Reference


Filters are chainable functions that modify the value of an expression. Ibis's builtin filters are listed below in function form; in each case, the first argument of the function is the expression the filter operates on.

Note that the filters listed here are simply the default filters built into Ibis.

You can define your own filter functions — custom filters are both extremely powerful and extremely easy to implement. You can find instructions for implementing your own custom filters here.

default

default(obj, fallback)

Returns obj if obj is truthy, otherwise returns fallback.

dtformat

dtformat(datetime, format='%Y-%m-%d %H:%M')

Formats a datetime object using the specified format string.

endswith

endswith(str, suffix)

Returns true if the string ends with the specified suffix.

escape

escape(str, quotes=True)

Replaces the following HTML syntax characters with their corresponding character entities: <, >, &, ', and ". This filter is also available under the aliases esc and e.

even

even(i)

Returns true if the integer i is even.

first

first(seq)

Returns the first element in a sequence.

firsth

firsth(str)

Returns the content of the first heading element in a string of HTML.

firstp

firstp(str)

Returns the content of the first <p> element in a string of HTML.

if_undefined

if_undefined(obj, fallback)

Returns obj if obj is defined, i.e. not an instance of the Undefined class. If obj is undefined, returns fallback.

index

index(seq, i)

Returns the ith element in a sequence.

is_defined

is_defined(obj)

Returns true if obj is defined, i.e. not an instance of the Undefined class, otherwise returns false.

join

join(seq, sep='')

Joins elements of a sequence with the specified separator string.

last

last(seq)

Returns the last element in a sequence.

len

len(seq)

Returns the length of a sequence.

lower

lower(str)

Converts the string str to lowercase.

odd

odd(i)

Returns true if the integer i is odd.

pprint

pprint(obj)

Pretty prints an object.

pygmentize

pygmentize(text, lang=None)

Applies syntax-highlighting to a string using Pygments. If no language is specified, Pygments will attempt to guess the correct lexer to use.

If Pygments is not installed or if an appropriate lexer cannot be found this filter will return the input text with any HTML special characters escaped.

random

random(seq)

Returns a random element from a sequence.

repr

repr(obj)

Returns the result of calling repr() on an object.

reversed

reversed(seq)

Returns a reverse iterator over a sequence.

slice

slice(seq, start, stop=None, step=None)

Returns the [start:stop:step] slice of a sequence.

spaceless

spaceless(str)

Strips all whitespace between HTML/XML tags in a string.

startswith

startswith(str, prefix)

Returns true if the string starts with the specified prefix.

str

str(obj)

Returns the result of calling str() on an object.

striptags

striptags(str)

Strips all HTML/XML tags from a string.

titlecase

titlecase(str)

Converts the string str to titlecase.

truncatechars

truncatechars(str, n, ellipsis='...')

Truncates the string str to at most n chars.

truncatewords

truncatewords(str, n, ellipsis=' [...]')

Truncates the string str to at most n words.

upper

upper(str)

Converts the string str to uppercase.

wrap

wrap(str, tag)

Wraps the string str in opening and closing tags.