Skip to content

Commit 3796442

Browse files
committed
Merge pull request Polymer#594 from robdodson/master
Add outer template to binding types examples
2 parents 7fe7393 + a437c54 commit 3796442

File tree

1 file changed

+66
-42
lines changed

1 file changed

+66
-42
lines changed

docs/polymer/binding-types.md

Lines changed: 66 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,11 @@ occurs. See [Node bindings](#node-bindings) for details.
3131
Using the `bind` attribute, you can create a single instance of a template bound to an object.
3232

3333
{% 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>
3739
</template>
3840
{% endraw %}
3941

@@ -45,9 +47,11 @@ if `person` has a property, `name`, {%raw%}`{{name}}`{%endraw%} evaluates to the
4547
For convenience, you can also create a _named scope_ when binding an object:
4648

4749
{% 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>
5155
</template>
5256
{% endraw %}
5357

@@ -64,8 +68,10 @@ an array. Each instance is bound to an item in the array.
6468
The simplest format for a repeating template is:
6569

6670
{% 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>
6975
</template>
7076
{% endraw %}
7177

@@ -75,18 +81,22 @@ the current binding scope. Refer to a property of the current item as {%raw%}`{{
7581
Like the `bind` attribute, the `repeat` attribute supports named scopes:
7682

7783
{% raw %}
78-
<template repeat="{{user in users}}">
79-
{{user.name}}
84+
<template>
85+
<template repeat="{{user in users}}">
86+
{{user.name}}
87+
</template>
8088
</template>
8189
{% endraw %}
8290

8391
When using named scopes with the `repeat` attribute, the index value for each
8492
item in the array is also available by using the following syntax:
8593

8694
{% 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>
90100
</template>
91101
</template>
92102
{% endraw %}
@@ -103,15 +113,17 @@ parent scope. For example, suppose you have an array of objects like this:
103113
You can use code like this to access both the array itself and its elements:
104114

105115
{% 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>
113126
</template>
114-
</ul>
115127
</template>
116128
{% endraw %}
117129

@@ -129,8 +141,10 @@ Item count: 3
129141
Conditional templates use the `if` attribute to conditionally create a template instance.
130142

131143
{% 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>
134148
</template>
135149
{% endraw %}
136150

@@ -141,9 +155,11 @@ Where the explicit binding is omitted, a nested template can inherit the scope o
141155
the containing template. Conditional templates are frequently used this way:
142156

143157
{% 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>
147163
</template>
148164
</template>
149165
{% endraw %}
@@ -153,9 +169,11 @@ For more information on nesting templates, see [Expression scopes](/docs/polymer
153169
You can also use `if` with the `repeat` attribute.
154170

155171
{% 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>
159177
</template>
160178
</template>
161179
{% endraw %}
@@ -166,34 +184,40 @@ Sometimes, you may want to reuse a template in multiple places, or reference a t
166184
That's where the `ref` attribute comes in:
167185

168186
{% 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>
172191

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>
176196
</template>
177197
{% endraw %}
178198

179199
You can use the `ref` attribute to define recursive templates, such as tree structures:
180200

181201
{% raw %}
182202
<template>
183-
<ul>
184-
<template repeat="{{items}}" id="t">
185-
<li>{{name}}
203+
<template>
186204
<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>
190212
</template>
191213
{% endraw %}
192214

193215
In addition, you can bind to the `ref` attribute _itself_, to choose templates dynamically:
194216

195217
{% raw %}
196-
<template bind ref="{{node.nodeType}}"></template>
218+
<template>
219+
<template bind ref="{{node.nodeType}}"></template>
220+
</template>
197221
{% endraw %}
198222

199223
## Node bindings

0 commit comments

Comments
 (0)