@@ -31,9 +31,11 @@ occurs. See [Node bindings](#node-bindings) for details.
31
31
Using the ` bind ` attribute, you can create a single instance of a template bound to an object.
32
32
33
33
{% raw %}
34
- <template bind =" {{person}} " >
35
- This template can bind to the person object’s properties, like
36
- {{name}}.
34
+ <template >
35
+ <template bind =" {{person}} " >
36
+ This template can bind to the person object’s properties, like
37
+ {{name}}.
38
+ </template >
37
39
</template >
38
40
{% endraw %}
39
41
@@ -45,9 +47,11 @@ if `person` has a property, `name`, {%raw%}`{{name}}`{%endraw%} evaluates to the
45
47
For convenience, you can also create a _ named scope_ when binding an object:
46
48
47
49
{% raw %}
48
- <template bind =" {{person as p}} " >
49
- This template uses a named scope to access properties, like
50
- {{p.name}}.
50
+ <template >
51
+ <template bind =" {{person as p}} " >
52
+ This template uses a named scope to access properties, like
53
+ {{p.name}}.
54
+ </template >
51
55
</template >
52
56
{% endraw %}
53
57
@@ -64,8 +68,10 @@ an array. Each instance is bound to an item in the array.
64
68
The simplest format for a repeating template is:
65
69
66
70
{% raw %}
67
- <template repeat =" {{array}} " >
68
- Creates an instance with {{}} bindings for every element in the array collection.
71
+ <template >
72
+ <template repeat =" {{array}} " >
73
+ Creates an instance with {{}} bindings for every element in the array collection.
74
+ </template >
69
75
</template >
70
76
{% endraw %}
71
77
@@ -75,18 +81,22 @@ the current binding scope. Refer to a property of the current item as {%raw%}`{{
75
81
Like the ` bind ` attribute, the ` repeat ` attribute supports named scopes:
76
82
77
83
{% raw %}
78
- <template repeat =" {{user in users}} " >
79
- {{user.name}}
84
+ <template >
85
+ <template repeat =" {{user in users}} " >
86
+ {{user.name}}
87
+ </template >
80
88
</template >
81
89
{% endraw %}
82
90
83
91
When using named scopes with the ` repeat ` attribute, the index value for each
84
92
item in the array is also available by using the following syntax:
85
93
86
94
{% raw %}
87
- <template repeat =" {{user, userIndex in users}} " >
88
- <template repeat =" {{userFile, userFileIndex in user}} " >
89
- {{userIndex}}:{{userFileIndex}}.{{userFile}}
95
+ <template >
96
+ <template repeat =" {{user, userIndex in users}} " >
97
+ <template repeat =" {{userFile, userFileIndex in user}} " >
98
+ {{userIndex}}:{{userFileIndex}}.{{userFile}}
99
+ </template >
90
100
</template >
91
101
</template >
92
102
{% endraw %}
@@ -103,15 +113,17 @@ parent scope. For example, suppose you have an array of objects like this:
103
113
You can use code like this to access both the array itself and its elements:
104
114
105
115
{% raw %}
106
- <template bind =" {{items}} " >
107
- // {{length}} evaluates as items.length
108
- <p >Item count: {{length}}</p >
109
- <ul >
110
- <template repeat >
111
- // {{name}} here evaluates as the name of a single item
112
- <li >{{name}}</li >
116
+ <template >
117
+ <template bind =" {{items}} " >
118
+ // {{length}} evaluates as items.length
119
+ <p >Item count: {{length}}</p >
120
+ <ul >
121
+ <template repeat >
122
+ // {{name}} here evaluates as the name of a single item
123
+ <li >{{name}}</li >
124
+ </template >
125
+ </ul >
113
126
</template >
114
- </ul >
115
127
</template >
116
128
{% endraw %}
117
129
@@ -129,8 +141,10 @@ Item count: 3
129
141
Conditional templates use the ` if ` attribute to conditionally create a template instance.
130
142
131
143
{% raw %}
132
- <template if =" {{conditionalValue}} " >
133
- Binds if and only if conditionalValue is truthy.
144
+ <template >
145
+ <template if =" {{conditionalValue}} " >
146
+ Binds if and only if conditionalValue is truthy.
147
+ </template >
134
148
</template >
135
149
{% endraw %}
136
150
@@ -141,9 +155,11 @@ Where the explicit binding is omitted, a nested template can inherit the scope o
141
155
the containing template. Conditional templates are frequently used this way:
142
156
143
157
{% raw %}
144
- <template bind =" {{myOptions as m}} " >
145
- <template if =" {{m.showCounter}} " >
146
- <div >Counter: {{m.counter}}</div >
158
+ <template >
159
+ <template bind =" {{myOptions as m}} " >
160
+ <template if =" {{m.showCounter}} " >
161
+ <div >Counter: {{m.counter}}</div >
162
+ </template >
147
163
</template >
148
164
</template >
149
165
{% endraw %}
@@ -153,9 +169,11 @@ For more information on nesting templates, see [Expression scopes](/docs/polymer
153
169
You can also use ` if ` with the ` repeat ` attribute.
154
170
155
171
{% raw %}
156
- <template bind =" {{myList as list}} " >
157
- <template repeat =" {{items in list.items}} " if =" {{list.showItems}} " >
158
- <li >{{item.name}}</li >
172
+ <template >
173
+ <template bind =" {{myList as list}} " >
174
+ <template repeat =" {{items in list.items}} " if =" {{list.showItems}} " >
175
+ <li >{{item.name}}</li >
176
+ </template >
159
177
</template >
160
178
</template >
161
179
{% endraw %}
@@ -166,34 +184,40 @@ Sometimes, you may want to reuse a template in multiple places, or reference a t
166
184
That's where the ` ref ` attribute comes in:
167
185
168
186
{% raw %}
169
- <template id =" myTemplate " >
170
- Used by any template which refers to this one by the ref attribute
171
- </template >
187
+ <template >
188
+ <template id =" myTemplate " >
189
+ Used by any template which refers to this one by the ref attribute
190
+ </template >
172
191
173
- <template bind ref="myTemplate">
174
- When creating an instance, the content of this template will be ignored,
175
- and the content of #myTemplate is used instead.
192
+ <template bind ref="myTemplate">
193
+ When creating an instance, the content of this template will be ignored,
194
+ and the content of #myTemplate is used instead.
195
+ </template>
176
196
</template>
177
197
{% endraw %}
178
198
179
199
You can use the ` ref ` attribute to define recursive templates, such as tree structures:
180
200
181
201
{% raw %}
182
202
<template >
183
- <ul >
184
- <template repeat =" {{items}} " id =" t " >
185
- <li >{{name}}
203
+ <template >
186
204
<ul >
187
- <template ref =" t " repeat =" {{children}} " ></template >
188
- </ul >
189
- </li >
205
+ <template repeat =" {{items}} " id =" t " >
206
+ <li >{{name}}
207
+ <ul >
208
+ <template ref =" t " repeat =" {{children}} " ></template >
209
+ </ul >
210
+ </li >
211
+ </template >
190
212
</template >
191
213
{% endraw %}
192
214
193
215
In addition, you can bind to the ` ref ` attribute _ itself_ , to choose templates dynamically:
194
216
195
217
{% raw %}
196
- <template bind ref =" {{node.nodeType}} " ></template >
218
+ <template >
219
+ <template bind ref =" {{node.nodeType}} " ></template >
220
+ </template >
197
221
{% endraw %}
198
222
199
223
## Node bindings
0 commit comments