Trees
A guide to creating a custom tree in Umbraco
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.
Creating trees
To create a Tree in the Backoffice, you need to take multiple steps:
Registering a tree
To register a tree, you need to create a manifest:
{
"type": "tree",
"alias": "My.Tree.Alias",
"name": "My Tree",
"meta": {
"repositoryAlias": "My.Repository.Alias"
}
}Rendering a tree
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.
Render a Custom Tree Item
The <umb-tree /> element will render the tree items based on the registered tree item alias. The tree will be rendered using the 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.
The Tree Item Manifest
The Tree Item Element
To create a custom tree item, you need to create a custom element. This element can optionally extend the UmbTreeItemElementBase class. However, it can also be used as a standalone element if you prefer to implement the tree item logic yourself.
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 Model
To define the data model for your tree item, you can create a model that extends the UmbTreeItemModel. This model will be used to provide the data for your custom tree item.
Adding data to the tree
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.
Implementing the repository
The repository needs to be able to fetch data for the tree. You can implement the repository as a class that extends the UmbTreeRepositoryBase class. This class provides the necessary methods to fetch data for the tree.
Implementing the data source
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 interface.
Further reading
For more information on trees, you can refer to the examples folder in the GitHub repository: Umbraco UI Examples - Trees
Last updated
Was this helpful?