Statements
Loop over each item in a sequence.
Inside of a for-loop block, you can access some special variables:
Macro are useful to put often used idioms into reusable component.
Note that macros are hoisted, and their scope is the toplevel scope. It means that you define two macro with the same name, the second will erase the first, even in the macro invocation occuring before the second definition.
Optionally, you can repeat the name of the macro in the endmacro
part.
Use call
statement to pass a macro to another macro.
Function can be seen as macros that return a value instead of printing it.
The if statement allows us to check if an expression is true or false, and execute different code according to the result.
0
, null
, ''
, ""
, []
,
or {}
are considered as false
when used in a if
/elif
test.
The rest is true
.
The switch statement allows us to use compare a variable with a set of literal values.
All blocks introduce a new scope when assigning variables. You can read a variable defined in a parent block, but you can not assign a new value to this variable. A new variable will be created for each assignment. It will shadow the old definition, but as soon as you will leave the block, the old definition
The only exception to that rule are if
statements which do not introduce a scope.
See Namespace for variable assignement propagating across scopes.
Namespace are used to create variables you can modify from a child block.
Use {%-
to strip whitespaces before this token.
Use -%}
to strip whitespaces after this token.
Tests
Tests are just functions that return a boolean.
Tests can be used with the standard function call syntax,
but also with the is
keyword in statements or expressions.
Operators
Evaluation of boolean operators is sequential, left-to-right.
In e1 && e2
,
e1
is evaluated first, and if it returns false
,
e2
is not evaluated at all.
In e1 || e2
,
e1
is evaluated first, and if it returns true
, e2
is not evaluated at all.
Use not
and !
operators to negate a boolean.
The fat arrow operator =>
is used to define anonymous functions.
It is right associative and have the lowest precedence of all the operators.
Built-in filters
abs (num)
Return the absolute value of num
.
attr (name, obj)
{{ foo | attr ("bar") }}
is {{ foo.bar }}
.
{{ foo | attr ("bar.baz") }}
is {{ foo.bar.baz }}
.
compose (f, g)
The composition function. compose (f, g)) (x)
is f (g (x))
.
default (default_value, value)
Return value
if it is defined from null
,
and default
otherwise.
escape (string)
. Replaces &
, "
,
<
and >
with their corresponding HTML entities.
exists (fn, seq)
groupby (fn, seq)
join (sep, seq)
last (seq)
.
Return the last element of sequence seq
.
length (seq)
.
Return the number of elements in sequence seq
.
printf(fmt, a1, a2, ..., aN)
Fill fmt
with a1
a2
... aN
.
Support a subset of OCaml format
type: %d
%s
and %f
.
NB: %s
would accept any type as long as it can to represented as a string.
range (start, stop)
replace (src, dst, s)
The syntax for regular expressions is the same as in Gnu Emacs.
Return a string identical to s
except that all substrings of s
that match regexp src
have been replaced by dst
.
The replacement template dst
can contain
\1
, \2
, etc;
these sequences will be replaced by the text matched by the corresponding
group in the regular expression src
.
\0
stands for the text matched by the whole regular expression.
Note: in src
and dst
any backslash character in the regular expression
must be doubled to make it past the Jingoo string parser.
In particular, if you want a regular expression that matches a single
backslash character, you need to quote it by adding a second
backslash. Then you need to quote both backslashes (according to the
syntax of string constants in Jingoo) by doubling them again, so you
need to write four backslash characters: "\\\\"
.
round (method, val)
. method
can be "floor"
or "ceil"
.
Mark a string value as safe: it won't be escaped.
sort (seq)
. Support the following optionnal keywords:
strlen (string)
. Number of UTF-8 characters.