Skip to content

Commit ffd614b

Browse files
authored
Merge pull request #401 from telerik/panelbar-content-template
docs: Improve ContentTemplate information
2 parents 075e256 + 9146cba commit ffd614b

File tree

3 files changed

+26
-38
lines changed

3 files changed

+26
-38
lines changed

components/panelbar/data-binding/overview.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,11 +194,13 @@ The following **Example** shows how to define simple binding to match item field
194194

195195
You can define different binding settings for the different levels of nodes in the PanelBar. With this, the children of a node can consume a different field than their parent, and this may make your application more flexible. If you use [hierarchical data binding]({%slug panelbar-data-binding-hierarchical%}), the children can even use a different field or model from their parent.
196196

197-
This also allows you to define a different [`ItemTemplate`]({%slug panelbar-templates%}) for different levels.
197+
This also allows you to define different [header and content templates]({%slug panelbar-templates%}) for different levels.
198198

199199
To define multiple bindings, add multiple `PanelBarBinding` tags and define their `Level`.
200200

201-
If a certain level does not have an explicit data bindings tag, it will use the default one that has no level.
201+
There can be maximum one binding for each level and one ("default") binding without a level. If multiple same-level bindings are declared, the first one is used and the rest are ignored.
202+
203+
If a certain level does not have an explicit data binding tag, it will use the default one that has no level.
202204

203205
>caption How to use per-level data binding settings to change model fields
204206

components/panelbar/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ Each item in the PanelBar consists of a `Header` and `Content`. The image below
144144

145145
You can customize their rendering through the corresponding [Header Template]({%slug panelbar-templates-header%}) and [Content Template]({%slug panelbar-templates-content%}).
146146

147-
The content represents the items in the hierarchy that does not have children. If the items have children and the ContentTemplate is defined, the template will not render. The header contains the Text of the correponding data item (model).
147+
The content represents the items in the hierarchy that do not have children. If the items have children and the ContentTemplate is defined, the template will not render. The header contains the Text of the correponding data item (model).
148148

149149
![panelbar parts](images/panelbar-parts-overview.png)
150150

components/panelbar/templates/content.md

Lines changed: 21 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,38 @@ position: 10
1010

1111
## ContentTemplate
1212

13+
You can control and customize the rendering of the content items in the PanelBar with a `ContentTemplate`. Here is how to use it.
1314

14-
You can control and customize the rendering of the content items in the PanelBar. It provides a `context` object that you can cast to the type that the PanelBar is bound it.
15+
* The `ContentTemplate` is defined under the `PanelBarBinding` tag.
16+
* It provides a `context` object that you can cast to the type, which the PanelBar is bound to.
17+
* The template can include other Razor components or executable code.
18+
* Similar to [`PanelBarBinding`s]({%slug panelbar-data-binding-overview%}), there can be **one** `ContentTemplate` for all items at the same level. If the content of these items should be different, use conditional statements inside the template.
19+
* A `ContentTemplate` displays like a child item. It is rendered only for the items, which have no children.
1520

16-
The `ContentTemplate` is defined under the `PanelBarBinding` tag.
17-
18-
>caption Use the ContentTemplate to customize the content items
21+
>caption Use ContentTemplate to customize the content items
1922
2023
````CSHTML
21-
@* Customize the rendering of the content items *@
24+
@*Set Level 0, 1 or 2 to the PanelBarBinding to see how the content template appears for specific levels only.*@
25+
@*Without a Level, the ContentTemplate will be applied to all items that have no children, from all levels, which don't have their own binding.*@
2226
2327
<div style="width: 30%;">
2428
<TelerikPanelBar Data="@Items">
2529
<PanelBarBindings>
2630
<PanelBarBinding ItemsField="Items">
2731
<ContentTemplate>
28-
@{
32+
@{
2933
var item = context as PanelBarItem;
3034
31-
<div style="text-decoration: underline; color: blue">
32-
@item.Text
35+
<div style="padding: 8px 16px;">
36+
<span style="text-decoration: underline; color: blue;">
37+
content template for: @item.Text
38+
</span>
39+
<br />
40+
@if (item.Text == "Item 2")
41+
{
42+
<TelerikButton Primary="true">Nested Component</TelerikButton>
43+
}
44+
3345
</div>
3446
}
3547
</ContentTemplate>
@@ -68,40 +80,14 @@ The `ContentTemplate` is defined under the `PanelBarBinding` tag.
6880
new PanelBarItem()
6981
{
7082
Text = "Item 1.2.1"
71-
},
72-
new PanelBarItem()
73-
{
74-
Text = "Item 1.2.2"
75-
}
76-
}
77-
}
78-
}
79-
},
80-
new PanelBarItem()
81-
{
82-
Text = "Item 2",
83-
Items = new List<PanelBarItem>()
84-
{
85-
new PanelBarItem()
86-
{
87-
Text = "Item 2.1",
88-
Items = new List<PanelBarItem>()
89-
{
90-
new PanelBarItem()
91-
{
92-
Text = "Item 2.1.1"
9383
}
9484
}
95-
},
96-
new PanelBarItem()
97-
{
98-
Text = "Item 2.2"
9985
}
10086
}
10187
},
10288
new PanelBarItem()
10389
{
104-
Text = "Item 3"
90+
Text = "Item 2"
10591
}
10692
};
10793

0 commit comments

Comments
 (0)