Skip to content

Building with Wajha

Filters Reference

Every filter a theme can use, and every one it cannot. A filter's argument follows a colon — value|filter:argument — and filters chain left to right.

Everything on this page was checked against the engine, not copied from another platform's documentation. If a filter is not listed here, it is not available.

Text

FilterExampleResult for the example
upper{{ "abaya"|upper }}ABAYA
lower{{ "ABAYA"|lower }}abaya
title{{ "hello world"|title }}Hello World
capfirst{{ "hello"|capfirst }}Hello
truncatechars{{ s|truncatechars:8 }}Hello... for Hello world
truncatewords{{ s|truncatewords:2 }}the first two words, then ...
wordcount{{ "a b c"|wordcount }}3
cut{{ "a-b"|cut:"-" }}ab
striptags{{ "<b>x</b>"|striptags }}x
center, ljust, rjust{{ "x"|center:5 }}x padded to five characters
wordwrap{{ s|wordwrap:40 }}lines broken at 40 characters
urlencode{{ "héllo wörld"|urlencode }}h%C3%A9llo+w%C3%B6rld
escapejs{{ s|escapejs }}s made safe inside a JavaScript string
stringformat{{ 42|stringformat:"%05d" }}00042 — Go format verbs, not Python's

Arabic has no case, so upper, lower, title and capfirst leave Arabic text as it is. A heading styled with them looks deliberate in English and inconsistent in Arabic.

Lists

FilterExampleResult for xs = ["a","b","c"]
length{{ xs|length }}3
first{{ xs|first }}a
last{{ xs|last }}c
join{{ xs|join:", " }}a, b, c
slice{{ "abc"|slice:":2" }}ab
length_is{% if xs|length_is:3 %}true

Numbers

FilterExampleResult
add{{ 3|add:2 }}5
floatformat{{ 3.14159|floatformat:2 }}3.14
divisibleby{% if n|divisibleby:2 %}true when n is even
pluralize{{ n|pluralize }}s when n is not 1

pluralize only knows English plurals. Arabic has six plural forms; put the whole phrase in your locale files instead of building it.

Never use these on money. Every amount arrives as formatted — see Money, Dates & Numerals.

Defaults and choices

FilterExampleResult
default{{ s|default:"—" }}— when s is empty, 0 or missing
default_if_none{{ s|default_if_none:"—" }}— only when s is missing
yesno{{ in_stock|yesno:"yes,no" }}yes or no
FilterExampleResult
url<a href="{{ link|url }}">link when it is safe in an href, otherwise #

Use it on every value you did not write yourself that goes into href or src. It accepts http: and https: URLs with a host, mailto: and tel: links, and paths on the store that start with a single /. It refuses everything else — javascript:, data:, a protocol-relative //other-site, and any value containing whitespace or a control character, since browsers ignore those inside a scheme and java script: would otherwise run.

Refused

A theme using any of these is refused when it is loaded, with the file and line:

FilterWhy
safeIt switches escaping off
truncatechars_html, truncatewords_htmlThey return their input as unescaped HTML
urlize, urlizetruncThey generate markup, with an option to skip escaping
linebreaks, linebreaksbrEscaping prints the tags they add as text — use CSS white-space: pre-line
date, timeDates arrive pre-formatted; Wajha's own date filter is not available yet

Coming

money, number and date (Wajha's own, with named formats), and rich. They are described where they matter — Money, Dates & Numerals and Security Model — and will be listed here when they ship.