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
Copy file name to clipboardExpand all lines: 16/umbraco-cms/customizing/extending-overview/extension-types/tree.md
+42-24Lines changed: 42 additions & 24 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,11 @@ description: A guide to creating a custom tree in Umbraco
8
8
This page is a work in progress and may undergo further revisions, updates, or amendments. The information contained herein is subject to change without notice.
9
9
{% endhint %}
10
10
11
-
The tree is a hierarchical structure of nodes and is registered in the Backoffice extension registry. A tree can be rendered anywhere in the Backoffice with the help of the umb-tree element.
11
+
The tree is a hierarchical structure of nodes and is registered in the Backoffice extension registry. A tree can be rendered anywhere in the Backoffice with the help of the `<umb-tree />` element.
12
+
13
+
{% hint style="info" %}
14
+
If you are looking for information on how to register a tree as a menu in a section, please refer to the [Section Sidebar](./sections/section-sidebar.md) article.
15
+
{% endhint %}
12
16
13
17
## Creating trees <ahref="#creating-trees"id="creating-trees"></a>
14
18
@@ -20,51 +24,58 @@ The backoffice comes with two different tree item kinds out of the box: entity a
20
24
21
25
Tree Manifest:
22
26
23
-
```typescript
24
-
// TODO: add interface
27
+
```json
25
28
{
26
-
"type": "tree",
27
-
"alias": "My.Tree.Alias",
28
-
"name": "My Tree",
29
-
"meta": {
30
-
"repositoryAlias": "My.Repository.Alias"
31
-
}
29
+
"type": "tree",
30
+
"alias": "My.Tree.Alias",
31
+
"name": "My Tree",
32
+
"meta": {
33
+
"repositoryAlias": "My.Repository.Alias"
34
+
}
32
35
},
33
36
{
34
-
"type": "treeItem",
35
-
"kind": "entity",
36
-
"alias": "My.TreeItem.Alias",
37
-
"name": "My Tree Item",
38
-
"conditions": {
39
-
"entityType": "my-entity-type",
40
-
},
37
+
"type": "treeItem",
38
+
"kind": "entity",
39
+
"alias": "My.TreeItem.Alias",
40
+
"name": "My Tree Item",
41
+
"conditions": {
42
+
"entityType": "my-entity-type",
43
+
},
41
44
}
42
45
```
43
46
44
47
### Rendering a tree <ahref="#rendering-a-tree"id="rendering-a-tree"></a>
45
48
49
+
To render a tree in the Backoffice, you can use the `<umb-tree>` element. You need to provide the alias of the tree you want to render. The alias is the same as the one you registered in the manifest.
50
+
46
51
```typescript
47
52
<umb-treealias="My.Tree.Alias"></umb-tree>
48
53
```
49
54
50
55
### Render a Custom Tree Item <ahref="#render-a-custom-tree-item"id="render-a-custom-tree-item"></a>
51
56
57
+
The `<umb-tree />` element will render the tree items based on the registered tree item alias. If you want to render a custom tree item, you need to register a tree item manifest. This manifest can then show a custom element for the tree item.
58
+
52
59
#### **The Tree Item Manifest**
53
60
54
-
```typescript
61
+
```json
55
62
{
56
-
"type": "treeItem",
57
-
"alias": "Umb.TreeItem.Alias",
58
-
"name": "My Tree Item",
59
-
"element": "./my-tree-item.element.js",
60
-
"conditions": {
61
-
"entityType": "my-entity-type",
62
-
},
63
+
"type": "treeItem",
64
+
"alias": "Umb.TreeItem.Alias",
65
+
"name": "My Tree Item",
66
+
"element": "./my-tree-item.element.js",
67
+
"conditions": {
68
+
"entityType": "my-entity-type",
69
+
},
63
70
};
64
71
```
65
72
66
73
#### The Tree Item Element <ahref="#the-tree-item-element"id="the-tree-item-element"></a>
67
74
75
+
To create a custom tree item, you need to create a custom element. This element can choose to use the `<umb-tree-item-base>` element underneath. However, it can also be used as a standalone element if you prefer to implement the tree item logic yourself.
76
+
77
+
In this example, we will create a custom tree item that uses the `<umb-tree-item-base>` element. This base element provides the necessary context and functionality for the tree item.
#### The Tree Item Context <ahref="#the-tree-item-context"id="the-tree-item-context"></a>
98
110
111
+
The tree item context is a class that provides the necessary functionality for the tree item. It is used to manage the state of the tree item, such as loading children, selecting, and deselecting the item.
112
+
113
+
You can create a custom tree item context by implementing the `UmbTreeItemContext<T>` interface.
#### Extending the Tree Item Context base <ahref="#extending-the-tree-item-context-base"id="extending-the-tree-item-context-base"></a>
130
146
147
+
The easiest way to create a custom tree item context is to extend the `UmbTreeItemContextBase<T>` class. This class provides a lot of the functionality you need out of the box, such as loading children, selecting, and deselecting the item.
148
+
131
149
We provide a base class for the tree item context. This class provides some default implementations for the context. You can extend this class to overwrite any of the default implementations.
0 commit comments