You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tags are indicated by the double mustaches. `{{name}}` is a tag. Let's talk
143
-
about the different types of tags.
56
+
The engine will start a process named `ai_mustache_loader` to manage the templates under given directory.
144
57
145
-
### Variables
58
+
If a template is a parials, the filename must be prefixed with underscore.
146
59
147
-
The most basic tag is the variable. A `{{name}}` tag in a basic template will
148
-
try to call the `name` function on your view. By default a variable "miss"
149
-
returns an empty string.
60
+
The engine can load the templates without `ai_mustche:prepare`, but I recommand that call this fucation once after the tmeplate engine is started. Because the engine use only one `gen_server` to load template which may be very slow when the request is arrived.
150
61
151
-
All variables are HTML escaped by default. If you want to return unescaped
152
-
HTML, use the triple mustache: `{{{name}}}`.
153
62
154
-
### Boolean Sections
155
63
156
-
A section begins with a pound and ends with a slash. That is,
157
-
`{{#person}}` begins a "person" section while `{{/person}}` ends it.
64
+
## Erlang版Mustache编译器
158
65
159
-
If the `person` method exists and calling it returns `false`, the HTML
160
-
between the pound and slash will not be displayed.
If the `person` method exists and calling it returns `true`, the HTML
163
-
between the pound and slash will be rendered and displayed.
68
+
当前该版本是一个比较早期的版本,在内部虽然得到部分使用,但依然存在一定量的Bug,请谨慎使用
164
69
165
70
166
-
### List Sections
71
+
### 最简单的例子
167
72
168
-
List sections are syntactically identical to boolean sections in that they
169
-
begin with a pound and end with a slash. The difference, however, is in the
170
-
view: if the function called returns a list, the section is repeated as the
171
-
list is iterated over.
73
+
这个例子只是在Erlang的REPL中使用一个字符串和一个简单的context。
172
74
173
-
Each item in the enumerable is expected to be a map that will then become the
174
-
context of the corresponding iteration. In this way we can construct loops.
175
-
176
-
For example, imagine this template:
177
-
178
-
{{#repo}}
179
-
<b>{{name}}</b>
180
-
{{/repo}}
181
-
182
-
And this view code:
183
-
184
-
repo() ->
185
-
[map:from_list([{<<"name">>, Name}]) || Name <- ["Tom", "Chris", "PJ"]].
186
-
187
-
When rendered, our view will contain a list of each of the names in the source list. When left the section, the context will be restored, the view will not contain the names anymore.
188
-
189
-
### Inverted Sections
190
-
An inverted section begins with a caret (hat) and ends with a slash. That is {{^person}} begins a "person" inverted section while {{/person}} ends it.
191
-
192
-
While sections can be used to render text one or more times based on the value of the key, inverted sections may render text once based on the inverse value of the key. That is, they will be rendered if the key doesn't exist, is `false`, or is an empty list `[]`.
193
-
194
-
### Comments
195
-
196
-
Comments begin with a bang and are ignored. The following template:
197
-
198
-
<h1>Today{{! ignore me }}.</h1>
199
-
200
-
Will render as follows:
201
-
202
-
<h1>Today.</h1>
203
-
204
-
### Partials
205
-
206
-
Partials begin with a greater than sign, like {{> box}}.
207
-
208
-
Partials are rendered at runtime (as opposed to compile time), so recursive partials are possible. Just avoid infinite loops.
209
-
210
-
They also inherit the calling context.
211
-
212
-
In this way you may want to think of partials as includes, imports, template expansion, nested templates, or subtemplates, even though those aren't literally the case here.
0 commit comments