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
@@ -4,138 +4,197 @@ description: A guide to creating a custom tree in Umbraco
4
4
5
5
# Trees
6
6
7
-
{% hint style="warning" %}
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
-
{% endhint %}
7
+
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.
10
8
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.
9
+
{% hint style="info" %}
10
+
To see how to register a tree as a menu in a section, please refer to the [Section Sidebar](./sections/section-sidebar.md) article.
11
+
{% endhint %}
12
12
13
13
## Creating trees <ahref="#creating-trees"id="creating-trees"></a>
14
14
15
-
To Create a Tree in a section of the Umbraco backoffice, you need to take multiple steps:
15
+
To create a Tree in the Backoffice, you need to take multiple steps:
16
16
17
17
### Registering a tree <ahref="#registering-a-tree"id="registering-a-tree"></a>
18
18
19
-
The backoffice comes with two different tree item kinds out of the box: entity and fileSystem.
19
+
To register a tree, you need to create a manifest:
20
20
21
-
Tree Manifest:
22
-
23
-
```typescript
24
-
// TODO: add interface
21
+
```json
25
22
{
26
-
"type": "tree",
27
-
"alias": "My.Tree.Alias",
28
-
"name": "My Tree",
29
-
"meta": {
30
-
"repositoryAlias": "My.Repository.Alias"
31
-
}
32
-
},
33
-
{
34
-
"type": "treeItem",
35
-
"kind": "entity",
36
-
"alias": "My.TreeItem.Alias",
37
-
"name": "My Tree Item",
38
-
"conditions": {
39
-
"entityType": "my-entity-type",
40
-
},
23
+
"type": "tree",
24
+
"alias": "My.Tree.Alias",
25
+
"name": "My Tree",
26
+
"meta": {
27
+
"repositoryAlias": "My.Repository.Alias"
28
+
}
41
29
}
42
30
```
43
31
44
32
### Rendering a tree <ahref="#rendering-a-tree"id="rendering-a-tree"></a>
45
33
34
+
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.
35
+
46
36
```typescript
47
37
<umb-treealias="My.Tree.Alias"></umb-tree>
48
38
```
49
39
50
40
### Render a Custom Tree Item <ahref="#render-a-custom-tree-item"id="render-a-custom-tree-item"></a>
51
41
42
+
The `<umb-tree />` element will render the tree items based on the registered tree item alias. The tree will be rendered using the [<umb-default-tree-item />](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_tree.UmbDefaultTreeItemElement.html) element by default. 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.
43
+
52
44
#### **The Tree Item Manifest**
53
45
54
-
```typescript
46
+
```json
55
47
{
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
-
},
48
+
"type": "treeItem",
49
+
"alias": "Umb.TreeItem.Alias",
50
+
"name": "My Tree Item",
51
+
"element": "./my-tree-item.element.js",
52
+
"conditions": {
53
+
"entityType": "my-entity-type",
54
+
},
63
55
};
64
56
```
65
57
66
58
#### The Tree Item Element <ahref="#the-tree-item-element"id="the-tree-item-element"></a>
67
59
60
+
To create a custom tree item, you need to create a custom element. This element can optionally extend the [UmbTreeItemElementBase<T>](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_tree.UmbTreeItemElementBase.html) class. However, it can also be used as a standalone element if you prefer to implement the tree item logic yourself.
61
+
62
+
This example creates a custom tree item that extends the base class. The base class 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>
85
+
#### The Tree Item Model <ahref="#extending-the-tree-item-model"id="extending-the-tree-item-model"></a>
98
86
87
+
To define the data model for your tree item, you can create a model that extends the [UmbTreeItemModel](https://apidocs.umbraco.com/v16/ui-api/interfaces/packages_core_tree.UmbTreeItemModel.html). This model will be used to provide the data for your custom tree item.
// Add any additional properties you need for your tree item
95
+
}
96
+
```
97
+
{% endcode %}
98
+
99
+
100
+
### Adding data to the tree <ahref="#adding-data-to-the-tree"id="adding-data-to-the-tree"></a>
101
+
102
+
To add data to the tree, you need to create a repository that will provide the data for the tree. The repository is defined in the manifest of the tree and linked through its `repositoryAlias`.
103
+
104
+
```json
105
+
{
106
+
"type": "repository",
107
+
"alias": "My.Repository.Alias",
108
+
"name": "My Repository",
109
+
"api": "./my-repository.js"
126
110
}
127
111
```
128
112
129
-
#### Extending the Tree Item Context base <ahref="#extending-the-tree-item-context-base"id="extending-the-tree-item-context-base"></a>
113
+
#### Implementing the repository <ahref="#implementing-the-repository"id="implementing-the-repository"></a>
130
114
131
-
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.
115
+
The repository needs to be able to fetch data for the tree. You can implement the repository as a class that extends the [UmbTreeRepositoryBase](https://apidocs.umbraco.com/v16/ui-api/classes/packages_core_tree.UmbTreeRepositoryBase.html) class. This class provides the necessary methods to fetch data for the tree.
#### Implementing the data source <ahref="#implementing-the-data-source"id="implementing-the-data-source"></a>
132
+
133
+
The data source is responsible for fetching the data for the tree. You can implement the data source as a class that implements the [UmbTreeDataSource](https://apidocs.umbraco.com/v16/ui-api/interfaces/packages_core_tree.UmbTreeDataSource.html) interface.
138
134
139
-
// overwrite any methods or properties here if needed
## Further reading <ahref="#further-reading"id="further-reading"></a>
199
+
200
+
For more information on trees, you can refer to the examples folder in the GitHub repository: [Umbraco UI Examples - Trees](https://github.com/umbraco/Umbraco-CMS/tree/main/src/Umbraco.Web.UI.Client/examples/tree)
0 commit comments