-
Notifications
You must be signed in to change notification settings - Fork 1k
/
Copy pathadvancedsnippet.txt
135 lines (97 loc) · 2.52 KB
/
advancedsnippet.txt
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
Advanced templating: illustrates defines and includes.
Include external snippet defined in a variable:
{{#def.externalsnippet}}
Load external template from a file:
{{#def.loadfile('/snippet.txt')}}
Load external template from a file and cache in a variable:
{{#def['snippet.txt'] || (def['snippet.txt'] = def.loadfile('/snippet.txt'))}}
Use cached file again:
{{#def['snippet.txt']}}
Here is a def block that will be used later. This snippet can be referenced from external templates too:
{{##def.snippet1:
Some snippet that will be included {{#def.a}} later {{=it.f1}}
#}}
First use of snippet1:
{{#def.snippet1}}
Second use of snippet1:
{{#def.snippet1}}
Include snippet1 if true:
{{# true && def.snippet1 }}
Runtime and Compile time evaluation used together:
{{= it.f3 + {{#def.a + def.b}} }}
Include xyz or insert 'not found':
{{#def.xyz || 'not found'}}
Set xyz to 1 and exclude result from output:
{{##def.xyz=1#}} is identical to {{#(def.xyz=1) && ""}}
Compare xyz to 1, show 'xyz is not 1' if false:
{{#def.xyz === 1 || 'xyz is not 1'}}
{{ if ({{#!def.abc}}) { }}
{{#def.abc}} is falsy
{{ } }}
{{ if ({{#def.xyz === 1}}) { }}
if(true) block
{{ } }}
{{##def.fntest = function() {
return "Function test worked!";
}
#}}
{{#def.fntest()}}
Conditionals:
{{? !it.altEmail }}
<p>
second email: {{= it.altEmail }}
</p>
{{?? true }}
else case worked
{{?}}
Array iterators
{{~ it.farray :p }}
<h1>{{=p.farray}}<h1>
{{~ p.farray :value:i }}
<h2>{{=i}}: {{=value}}</h2>
{{~ value :w }}
<h3>{{=w}}</h3>
{{~}}
{{~}}
{{~}}
{{~ ["apple", "banana", "orange"] :k}}
{{=k}}
{{~}}
{{~ (function(){ return [1,2,3]})() :k}}
{{=k}}
{{~}}
{{ function children(it) { }}
{{?it.Nodes.length}}
<ul>
{{~ it.Nodes :p}}
<li>
{{=p.title}}
{{children(p);}}
</li>
{{~}}
</ul>
{{?}}
{{ } }}
{{ children( {Nodes:[ {title:"1.1", Nodes:[ {title:"1.1.1", Nodes:[]}, {title:"1.1.2", Nodes:[]}] }, { title:"1.2", Nodes:[]}, { title:"1.3", Nodes:[]}], title:"1" } ); }}
{{##def.block:param:
<div>{{=param}}</div>
#}}
{{##def.block1:param:
<div>{{=param.a}}</div>
#}}
{{#(def.block:'text' || '') + def.block:5}}
{{#def.block:it.f3 || ''}}
{{#def.block:"lala tralala" || ''}}
{{#def.block1:{a:1, b:2} || ''}}
{{##def.testFunctionWithParam = function(str) {
return "My name is: " + str;
}
#}}
{{##def.mytestparam: {{=it.name}} #}}
{{#def.testFunctionWithParam(def.mytestparam)}}
{{#def.testFunctionWithParam("\{\{=it.name\}\}")}}
{{##def.testParamDef:myparam:
My name is: {{=myparam}}
#}}
{{#def.testParamDef:it.name}}
The end