Skip to content

Built-in Filters (84)

binja includes 84 built-in filters covering both Jinja2 and Django Template Language.

String Filters (26)

FilterDescriptionExample
upperUppercase{{ "hello"|upper }}HELLO
lowerLowercase{{ "HELLO"|lower }}hello
capitalizeFirst letter uppercase{{ "hello"|capitalize }}Hello
capfirstFirst char uppercase{{ "hello"|capfirst }}Hello
titleTitle case{{ "hello world"|title }}Hello World
trimStrip whitespace{{ " hi "|trim }}hi
striptagsRemove HTML tags{{ "<p>Hi</p>"|striptags }}Hi
slugifyURL-friendly slug{{ "Hello World!"|slugify }}hello-world
truncatecharsTruncate to N chars{{ "hello"|truncatechars:3 }}hel...
truncatewordsTruncate to N words{{ "a b c d"|truncatewords:2 }}a b...
truncatechars_htmlTruncate preserving HTMLPreserves HTML tags
truncatewords_htmlTruncate words in HTMLPreserves HTML tags
wordcountCount words{{ "hello world"|wordcount }}2
wordwrapWrap at N chars{{ text|wordwrap:40 }}
centerCenter in N chars{{ "hi"|center:10 }} hi
ljustLeft justify{{ "hi"|ljust:10 }}hi
rjustRight justify{{ "hi"|rjust:10 }} hi
cutRemove substring{{ "hello"|cut:"l" }}heo
replaceReplace substring{{ "hello"|replace:"l","x" }}hexxo
indentIndent lines{{ text|indent:4 }}
linebreaksNewlines to <p>/<br>Converts to HTML
linebreaksbrNewlines to <br>Converts to HTML
linenumbersAdd line numbersNumbers each line
addslashesEscape quotes{{ "it's"|addslashes }}it\'s
formatsprintf-style format{{ "Hi %s"|format:name }}
stringformatPython % format{{ 5|stringformat:"03d" }}005

Number Filters (9)

FilterDescriptionExample
absAbsolute value{{ -5|abs }}5
intConvert to integer{{ "42"|int }}42
floatConvert to float{{ "3.14"|float }}3.14
roundRound number{{ 3.7|round }}4
addAdd number{{ 5|add:3 }}8
divisiblebyCheck divisibility{{ 10|divisibleby:2 }}true
floatformatFormat decimal places{{ 3.14159|floatformat:2 }}3.14
filesizeformatHuman file size{{ 1048576|filesizeformat }}1.0 MB
get_digitGet Nth digit{{ 12345|get_digit:2 }}4

List/Array Filters (22)

FilterDescriptionExample
lengthList length{{ items|length }}3
length_isCheck length{{ items|length_is:3 }}true
firstFirst item{{ items|first }}
lastLast item{{ items|last }}
joinJoin with separator{{ items|join:", " }}a, b, c
sliceSlice list{{ items|slice:":2" }}
reverseReverse list{{ items|reverse }}
sortSort list{{ items|sort }}
uniqueRemove duplicates{{ items|unique }}
batchGroup into batches{{ items|batch:2 }}
columnsSplit into columns{{ items|columns:3 }}
dictsortSort dict by key{{ dict|dictsort }}
dictsortreversedSort dict reversed{{ dict|dictsortreversed }}
groupbyGroup by attribute{{ items|groupby:"category" }}
randomRandom item{{ items|random }}
listConvert to list{{ value|list }}
make_listString to char list{{ "abc"|make_list }}
mapMap attribute{{ items|map:"name" }}
selectFilter by test{{ items|select:"even" }}
rejectReject by test{{ items|reject:"none" }}
selectattrFilter by attr test{{ items|selectattr:"active" }}
rejectattrReject by attr test{{ items|rejectattr:"hidden" }}

Math Filters (4)

FilterDescriptionExample
maxMaximum value{{ items|max }}
minMinimum value{{ items|min }}
sumSum of values{{ items|sum }}
attrGet attribute{{ item|attr:"name" }}

Date/Time Filters (4)

FilterDescriptionExample
dateFormat date{{ now|date:"Y-m-d" }}2024-01-15
timeFormat time{{ now|time:"H:i" }}14:30
timesinceTime since date{{ past|timesince }}2 days ago
timeuntilTime until date{{ future|timeuntil }}in 3 hours

Timezone Support

const env = new Environment({
timezone: 'Europe/Rome' // All dates in Rome timezone
})

Safety & Encoding Filters (13)

FilterDescriptionExample
escape / eHTML escape{{ html|escape }}
forceescapeForce HTML escape{{ html|forceescape }}
safeMark as safe{{ html|safe }}
safeseqMark sequence safe{{ items|safeseq }}
escapejsJS string escape{{ text|escapejs }}
urlencodeURL encode{{ url|urlencode }}
iriencodeIRI encode{{ url|iriencode }}
urlizeURLs to links{{ text|urlize }}
urlizetruncURLs to links (truncated){{ text|urlizetrunc:15 }}
json / tojsonJSON stringify{{ data|json }}
json_scriptSafe JSON in script{{ data|json_script:"id" }}
pprintPretty print{{ data|pprint }}
xmlattrDict to XML attrs{{ attrs|xmlattr }}

Default/Conditional Filters (4)

FilterDescriptionExample
default / dDefault value{{ missing|default:"N/A" }}
default_if_noneDefault if null{{ val|default_if_none:"None" }}
yesnoBoolean to text{{ true|yesno:"Yes,No" }}Yes
pluralizePluralize suffix{{ count|pluralize }}s

Misc Filters (2)

FilterDescriptionExample
itemsDict to pairs{% for k,v in dict|items %}
unordered_listNested list to HTML{{ items|unordered_list }}

Filter Chaining

Filters can be chained together:

{{ name|lower|capitalize|truncatechars:20 }}
{{ items|sort|reverse|join:", " }}
{{ price|floatformat:2|default:"N/A" }}