1 $group
2 $
3 var sect = {
4 title: 'Template engine'
5 };
6 section( §)
7 p ITTF Documents are composable templates,
8 \b and their nodes can contain template commands and
9 to-docs( JsWizzi )
10 + expressions.
11 p The buildup of an
12 to-docs( mTree )
13 + can repeat node branches using commands
14 \b like '$foreach', '$backeach' and '$while' and can include or exclude node branches
15 \b using '$if', '$elif' and '$else' commands.
16 p JsWizzi statements and expressions are executed in the evaluation context
17 \b of an ITTF Document code unit (file)
18 \b and may access global context variables.
19 ittf-panel
20 title The $foreach command
21 schema ittf
22 ittf
23 ...
24 ${'$'}foreach item-name in collection-name
25 ... node branch ...
26 p Descendant nodes of this command are a repeat template; item-name
27 \b is user defined and collection-name is a JsWizzi expression that must evaluate
28 \b to an iterable javascript object, in the fragment or global scope.
29 p The var statement that declares item-name is auto-generated.
30 p Descendant nodes are repeated having item-name as a value in scope.
31 ittf-panel
32 title The $while command
33 schema ittf
34 ittf
35 ...
36 ${'$'}while jswizzi-expression
37 ... node branch ...
38 ${'$'} jswizzi-exit-condition-change
39 p Descendant nodes are repeated
40 \b until the jswizzi-expression evaluates to false.
41 p $ or $global commands must be used to modify the context values of the exit condition.
42 \b There is a limit of 10000 iterations to guard against accidental loops, after that an exception is raised.
43 p TODO make the limit of 10000 iterations configurable and an optional parameter of the loadMTree function.
44 ittf-panel
45 title The $break, $continue commands
46 schema ittf
47 ittf
48 ...
49 ${'$'}foreach ...
50 ...
51 ${'$'}break
52 ...
53 ${'$'}continue
54 ...
55 ${'$'}$while ...
56 ...
57 ${'$'}break
58 p This statements have the same meaning than in javascript and operate
59 \b breaking or continuing the template repetition.
60 \b Labels for continuation are not implemented.