The filters, tests and operators of Jinja, Django, Nunjucks, Twig, Tera, Mailchimp, HubL and Klaviyo, which those languages' modules render with. They're Handlebars helpers, so a template converted to Handlebars renders with them too:
{:ok, source} = Braces.Django.convert("Hi {{ first_name|default:'friend'|title }}")
source
#=> "Hi {{title (default first_name \"friend\")}}"
Braces.Handlebars.render_to_string(Braces.Handlebars.compile!(source), %{}, helpers: Braces.Filters)
#=> {:ok, "Hi Friend"}Add your own helpers after them, helpers: [Braces.Filters, MyApp.EmailHelpers], for
filters that aren't here: a filter is converted to a helper of the same name.
Values are true unless they're nil, false, 0, "", [] or %{}, as in Python.
Comparisons compare numbers as numbers, and a number with a string that is a number, so
"18" equals 18, as Mailchimp's merge fields and Klaviyo's == 1 expect. Other values
are compared as strings.
Helpers
- Comparisons:
eq,ne,gt,gte,lt,lte,in(a list's element, a map's key, or a substring),and,or,not, andisfor HubL's tests (defined,undefined,none,truthy,even,odd,number,string,sequence,mapping,divisibleby,string_containing,string_startingwith,string_endingwith,empty,iterable,containing,boolean,true,false,integer,float,lower,upper,escaped,filter,test). - Text:
upper(upcase),lower(downcase),title,capitalize(capfirst),trim(withchars),truncate,truncate_after,replace(find_replace),striptags(strip_html),urlencode,escape(e,escape_html),safe,append,prepend,concat,split,string, and Jinja'swordcount,wordwrap,indent,center,format,filesizeformat,urlizeandxmlattr. - Lists:
length(size,count),join,first,last,reverse, and Jinja'ssort,list,unique,sum,min,max,batch,slice,map,select,reject,selectattr,rejectattr,groupby,dictsortanditems, with Jinja's keyword arguments as the hash:{{sort people attribute="name"}}.groupby,dictsortanditemsgive{key, value}tuples. - Numbers in words:
ordinal(3rd),number_words(three) andordinal_words(third), for numbers from 0 to 99. - Numbers:
add(plus),subtract(minus),multiply,divide,modulo,round,abs,int(withdefaultandbase),float(withdefault),floatformat. default: the value, or the fallback when the value isn't true. Withundefined: true, as Jinja'sdefaultwithout its second argument, only when it's missing; withempty: true, as Twig's, when it's missing,false,"",[]or%{}; withtruth:, when it's false by that language's rules, astruthy.truthy: whether a value is true, by Python's rules or a language's,(truthy x "liquid").- Dates:
dateformats a date with PHP's and Django's format characters, as*|DATE:d/m/y|*and Klaviyo's|date:'F j, Y';strftimeformats one with%Y-%m-%d;nowis the current time in UTC; andformat_date_stringreads an ISO 8601 string.
Summary
Functions
The items in lists of count, the last filled with fill when it's given.
The text in the middle of width characters, as Python's center.
A map's {key, value} pairs sorted by key, or by: "value", as Jinja's dictsort.
An empty list, for a template with no literal for one.
An empty map, for a template with no literal for one.
A number of bytes as text, as Jinja's filesizeformat: 3.0 kB, or with binary, 2.9 KiB.
a // b: the quotient rounded down, as Python's.
The text with %s, %d, %i, %f and %r replaced by the arguments, as Python's %
formats them.
The items in groups by their attribute, as Jinja's groupby: {grouper, items} pairs in
the groupers' order, read as group.grouper and group.list, or in a loop as
for grouper, items in …; default for an item without it, and case_sensitive.
Each line after the first indented by width spaces, or by width when it's text, as
Jinja's indent: first indents the first line too, and blank blank lines.
A map's {key, value} pairs, as Jinja's items.
A map's keys, or a list's indexes, as Twig's keys gives them.
A Liquid loop's limit:: the list's first count items.
A Liquid loop's offset:: the list after its first count items.
Liquid's range, (1..5): the integers from one to the other, both included.
A list of the value's items: a map's keys, or a string's characters.
Each item through a filter, map("upper"), or its attribute, map(attribute="name"),
with default for an item without it.
The largest item, as Jinja's max: case_sensitive, attribute.
The smallest item, as Jinja's min: case_sensitive, attribute.
a ** b: a to the power b.
The items a test is false for, reject("odd"), or that are false.
The items whose attribute a test is false for, or is false.
The items a test is true for, select("odd"), or that are true.
The items whose attribute a test is true for, or is true.
The items in count lists, as Jinja's slice, the shorter filled with fill.
A list sorted, as Jinja's sort: reverse, case_sensitive (false: "a" and "B" sort as
"a" and "b") and attribute, a key, a path, "a.b", or keys, "a,b", to sort items by.
Given in order or by name: {{sort xs true}}, {{sort xs attribute="name"}}. A map sorts its
keys.
Formats a date with strftime's format, %Y-%m-%d, as Tera's, Liquid's and Python's dates do.
The value as text.
The sum of the items, or of their attribute, from start.
The text without spaces, or the characters of chars, at its ends.
The first length characters, then ending when there were more, as Tera's truncate.
Whether a value is true by a language's rules, "python" when not given: see
Braces.IR.truth/0.
The items without repeats, the first of each kept, as Jinja's unique: case_sensitive,
attribute.
The text with its links, http://, https://, www. and domains, and email addresses as
<a> links, escaped, as Jinja's urlize: trim_url_limit, rel (noopener), target,
nofollow and extra_schemes.
How many words: runs of letters, digits and _.
The text in lines of at most width characters, as Jinja's wordwrap: each line of the
text wrapped on its own, joined with wrapstring, and words longer than a line broken
unless break_long_words is false.
A map as HTML attributes, as Jinja's xmlattr: key="value" for each key whose value
isn't missing or nil, escaped.
Functions
The items in lists of count, the last filled with fill when it's given.
The text in the middle of width characters, as Python's center.
A map's {key, value} pairs sorted by key, or by: "value", as Jinja's dictsort.
An empty list, for a template with no literal for one.
An empty map, for a template with no literal for one.
A number of bytes as text, as Jinja's filesizeformat: 3.0 kB, or with binary, 2.9 KiB.
a // b: the quotient rounded down, as Python's.
The text with %s, %d, %i, %f and %r replaced by the arguments, as Python's %
formats them.
The items in groups by their attribute, as Jinja's groupby: {grouper, items} pairs in
the groupers' order, read as group.grouper and group.list, or in a loop as
for grouper, items in …; default for an item without it, and case_sensitive.
Each line after the first indented by width spaces, or by width when it's text, as
Jinja's indent: first indents the first line too, and blank blank lines.
A map's {key, value} pairs, as Jinja's items.
A map's keys, or a list's indexes, as Twig's keys gives them.
A Liquid loop's limit:: the list's first count items.
A Liquid loop's offset:: the list after its first count items.
Liquid's range, (1..5): the integers from one to the other, both included.
A list of the value's items: a map's keys, or a string's characters.
Each item through a filter, map("upper"), or its attribute, map(attribute="name"),
with default for an item without it.
The largest item, as Jinja's max: case_sensitive, attribute.
The smallest item, as Jinja's min: case_sensitive, attribute.
a ** b: a to the power b.
The items a test is false for, reject("odd"), or that are false.
The items whose attribute a test is false for, or is false.
The items a test is true for, select("odd"), or that are true.
The items whose attribute a test is true for, or is true.
The items in count lists, as Jinja's slice, the shorter filled with fill.
A list sorted, as Jinja's sort: reverse, case_sensitive (false: "a" and "B" sort as
"a" and "b") and attribute, a key, a path, "a.b", or keys, "a,b", to sort items by.
Given in order or by name: {{sort xs true}}, {{sort xs attribute="name"}}. A map sorts its
keys.
Formats a date with strftime's format, %Y-%m-%d, as Tera's, Liquid's and Python's dates do.
The value as text.
The sum of the items, or of their attribute, from start.
The text without spaces, or the characters of chars, at its ends.
The first length characters, then ending when there were more, as Tera's truncate.
Whether a value is true by a language's rules, "python" when not given: see
Braces.IR.truth/0.
The items without repeats, the first of each kept, as Jinja's unique: case_sensitive,
attribute.
The text with its links, http://, https://, www. and domains, and email addresses as
<a> links, escaped, as Jinja's urlize: trim_url_limit, rel (noopener), target,
nofollow and extra_schemes.
How many words: runs of letters, digits and _.
The text in lines of at most width characters, as Jinja's wordwrap: each line of the
text wrapped on its own, joined with wrapstring, and words longer than a line broken
unless break_long_words is false.
A map as HTML attributes, as Jinja's xmlattr: key="value" for each key whose value
isn't missing or nil, escaped.