Statements
Itérer sur chaque élément d'une séquence.
A l'intérieur d'une boucle for
, vous pouvez acceder à certaines variables automatiques :
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.
Lors de l'assignement d'une variable dans un block, la portée de cette dernière se limite au block dans lequel elle a été défini (et à ses blocks enfants). C'est à dire que vous pouvez accéder aux variables définies dans un block parent, mais pas les redfinir. Une affectation masquera l'ancienne définition de la variable tant que vous ne serez au sein du block courant, mais à l'exterieur du block, la variable sera toujours affectée à l'ancienne valeur.
Seuls les blocks if
dérogent à la règle et modifie la variable du scope parent.
Voyez les namespaces pour des utiliser des variables modifiable par les blocks enfants.
Les namespaces peuvent être utilisés pour créer des variables modifiables depuis un block enfant.
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
L'évaluation des tests booléens est séquentiel, de gauche à droite.
Dans e1 && e2
,
e1
est évalué, et si e1
retourne false
, e2
n'est pas évalué du tout.
Dans e1 || e2
,
e1
est évalué, et si e1
retourne true
, e2
n'est pas évalué du tout.
Utilisez les opérateurs not
et !
pour inverser un booléen.
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.