forked from fastn-stack/ftd.dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathloop.ftd
76 lines (48 loc) · 1.49 KB
/
loop.ftd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/-- ft-core.concept:
-- ft.page-with-toc: `$loop$`: Looping Over Lists
toc: $config.api-toc
sub-sections: $config.doc-header
-- ft.markdown:
`ftd` supports [`list`](list/) data type, and we can render each
element of a list using `$loop$` construct.
Consider this list:
-- ft.code:
lang: ftd
\-- list people:
type: string
\-- people: Arpita
\-- people: Asit
\-- people: Sourabh
-- ft.markdown:
Here we defined a list of type `string`, with three elements. Now say we want to
display each of them:
-- ft.code:
lang: ftd
\-- ftd.text: ref obj
$loop$: people as obj
-- ft.markdown:
Notice the `$loop$`, which tells `ftd` to invoke the component
[`ftd.text`](text/), once for each member of our list.
We have looped over `people`, and in each instance of the loop, the current member
is called `obj`, notice the `as obj` modifier.
If no modifier is given, the name of each member of the list is `object`.
-- ft.h1: `if` with `$loop$`
We can further use `if` in the loop to only show some of the members of the list
that meet some criteria:
-- ft.code:
lang: ftd
\-- foo: ref $o.name
$loop$: employee as o
if: o.is-permanent
-- ft.markdown:
Here we are looping over a record containing `.name: string` and
`.is-permanent: boolean` and we only want to show employee names for permanent
employees.
-- ft.h1: Looping At Sub-Component Level
Looping is also allowed at the sub-component level:
-- ft.code:
lang: ftd
\-- ftd.column:
\--- foo: ref obj.name
$loop$: people as obj
body: ref obj.bio