-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.xtpl
More file actions
148 lines (124 loc) · 2.56 KB
/
example.xtpl
File metadata and controls
148 lines (124 loc) · 2.56 KB
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
136
137
138
139
140
141
142
143
144
145
146
147
148
{{ hello.foo }}
{{{ hello.html }}}
{{! TODO 这是注释在外部 }}
{{% {{x}} %}}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ hello.name }}<title>
{{require("mui/feloader/feloader-min")}}
<head>
<body>
{{! 这是注释 }}
<div id="username" class="username {{hello.name}}" data-{{value}} data-config='{{{ data.config }}}'>
{{ username }}
<div>
<script>
var foo = '{{ foo.value }}';
var html = '{{{ foo.html }}}'
console.log(foo, html);
</script>
<script type="text/xtpl">
{{! 输出原始的模板块 }}
{{% {{ foo.x }} %}}
</script>
<script type="text/xtpl">
{{! 输出原始的模板块 }}
{{%
{{#each (arr)}}
{{xindex}}
{{this.value}}
{{'hello'}}
{{/each}}
%}}
</script>
<h1>
{{require('hello')}}
</h1>
{{ data.username }}
{{ data['username'] }}
{{! 下面是 unescape 的语法 }}
unescaped: {{{ foo }}}
{{! 赋值语法 }}
{{ set x = 1 }}
{{ set y = 'hello, world' }}
{{ set (a = 1, b = 2) }}
{{ set arr = [1, 2, 'foo'] }}
{{! 删除前后空格 }}
{{set x='1'}}
{{set data=[1,2]}}
{{ x ~}} end
{{~#each(data) ~}}
{{this}}
{{~/each}}
{{! 块 }}
{{# each(arr)}}
{{ this }}
{{/ each}}
{{! 操作符 }}
{{ x + y }}
{{ x + 'foo' }}
{{ x - 1 }}
{{! 比较 }}
{{#if (x === 1) }}
1
{{ elseif (x > 3) }}
4
{{ elseif (x <= 3) }}
2
{{ else }}
other
{{/ if }}
{{! with }}
{{# with (a) }}
{{ b }}
{{/ with }}
{{! TODO array }}
{{set (array = [{
name: "foo"
}, {
name: "bar"
}])}}
{{#each(array)}}
{{xindex}} {{this.name}}
{{/each}}
{{! dictionaries }}
{{set (dictionary = {
foo: "bar",
hello: "world"
}) }}
{{#each(dictionary,"value","key")}}
{{key}} {{value}}
{{/each}}
{{! macro }}
{{#macro("test","param", default=1)}}
param is {{param}} {{default}}
{{/macro}}
{{ macro("test","2") }}
{{ macro("test", "2", default=2) }}
{{! include }}
{{ include ("sub.html", xx = x, yy = x)}}
{{ includeOnce ("sub.html", xx = x, yy = x)}}
{{! parse }}
{{ parse ("sub.html", xx = undefined, yy = null)}}
{{! block }}
{{{ block('head') }}}
{{#block('head')}}
head goes here
{{/block}}
{{ require("hello") }}
<script type="text/xtpl">
{{%
{{set a = 1}}
<h3 style="color: {{data.color}}">{{data.title}}</h3>
{{#each(data.arr)}}
<li>
<img src="{{this.img}}" alt="{{this.title}}">
<div>{{this.name}}</div>
<li>
{{/each}}
%}}
</script>
<body>
<html>