Trees
A guide to creating a custom tree in Umbraco
This section describes how to work with and create trees with Umbraco APIs.
Creating trees
To Create a Tree in a section of the Umbraco backoffice, you need to take multiple steps:
Create a TreeController class in C#. A new controller which inherits from the abstract Umbraco.Cms.Web.BackOffice.Trees.TreeController class and provides an implementation for two abstract methods:
GetTreeNodes (returns a
TreeNodeCollection) - Responsible for rendering the content of the tree structure;GetMenuForNode (returns a
MenuItemCollection) - Responsible for returning the menu structure to use for a particular node within a tree.
You will need to add a constructor as TreeController requires this. See full code snippet in the "Implementing the Tree" section below.
The Tree attribute used to decorate the TreeController has multiple properties.
SectionAlias- Alias of the section in which the tree appearsTreeAlias- Alias of the treeTreeTitle- The title of the treeTreeGroup- The tree group, the tree belongs toSortOrder- Sort order of the tree
For example:
[Tree("settings", "favouriteThingsAlias", TreeTitle = "Favourite Things Name", TreeGroup="favouritesGroup", SortOrder=5)]
public class FavouriteThingsTreeController : TreeController
{ }The example above would register a custom tree with a title 'Favourite Things Name' in the Settings section of Umbraco. It will be visiable inside a custom group called 'Favourites'.
Tree Groups
Tree Groups enable you to group trees in a section. You provide the alias of the Tree Group name, you wish to add your tree to. See Constants.Trees.Groups for a list of existing group alias. An example of tree groups in the backoffice would be the Settings tree group and the Templating tree group in the Settings section.
If you add your own alias, you'll need to add a translation key. This can be done by adding a language file to a lang folder with your application folder in App_Plugins: App_Plugins/favouriteThings/lang/en-us.xml. This will avoid the alias appearing as the header in [square brackets].
The language file should contain the following XML:
Customising the Root Tree Node
The first node in the tree is referred to as the Root Node. You can customise the Root Node by overriding the abstract CreateRootNode method. You can assign a custom icon to the Root Node. You can also specify a custom URL route path in the backoffice to use with your custom tree. The method can be useful if your section has a single node (single page app).
See Also: How to create your own custom section
Implementing the Tree
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.

Responding to Tree Actions
The actions on items in an Umbraco Tree will trigger a request to load a view, with a name corresponding the name of the action. From a subfolder of the views folder matching the name of the 'customTreeAlias'.
Clicking on one of the 'Favourite Things' in the custom tree example will load an edit.html view from the folder: /views/favouriteThingsAlias/edit.html. The 'Delete' menu item would also load a view from: /views/favouriteThingsAlias/delete.html
When creating a custom tree as part of a Umbraco package, it is recommended to change the location of the default folder. It should be changed to the App_Plugins folder. You achieve this by decorating your MVC TreeController with the PluginController attribute.
The edit view in the example would now be loaded from the location: /App_Plugins/favouriteThings/backoffice/favouriteThingsAlias/edit.html
Providing functionality in your Tree Action Views
You can instruct the Umbraco backoffice to load additional JavaScript resources (eg. AngularJS controllers) to use in conjunction with your 'tree action views' by adding a package.manifest file in the same folder location as your views.
For example...
...this manifest would load files for two controllers to work with the edit and delete views and a general resource file. Those files perhaps containing code to retrieve, create, edit and delete 'favourite things' from some external non-Umbraco API.
Our Tree Action View would then be wired to the loaded controller using the ng-controller attribute. The delete view would perhaps the delete view look a little bit like this:

Take a look at the umbEditor directives in the backoffice API Documentation, for lots of common interaction directives. Those directives can be used to deliver a consistent backoffice editing experience for items in your custom tree.
see Tree Actions for a list of tree ActionMenuItems and IActions
Single Node Trees / Customising the Root Node Action
It is possible to create 'trees' consisting of only a single node. Perhaps you want to do this to provide an area to control some settings or a placeholder for a single page backoffice app. See the LogViewer in the settings section for a good example. (in the case of the 'content templates' tree, it's possible to have a custom view for the root node).
In both scenarios you need to override the CreateRootNode method for the custom tree.
You can override the CreateRootNode method to set the 'RoutePath' to where the single page application will live (or introduction page). Setting HasChildren to false will result in a Single Node Tree.
The RoutePath should be in the format of: section/treeAlias/method. As our example controller uses the PluginController attribute, clicking the root node would now request /App_Plugins/favouriteThing/backoffice/favouritistThingsAlias/overview.html. If you are not using the PluginController attribute, then the request would be to /umbraco/views/favouritistThingsAlias/overview.html.

Full Width App - IsSingleNodeTree
It's possible to make your single node tree app stretch across the full screen of the backoffice (no navigation tree). See the Packages section for an example. To achieve this add an additional attribute IsSingleNodeTree, in the Tree attribute for the custom controller.
Tree notifications
All tree notications are defined in the namespace Umbraco.Cms.Core.Notifications.
For more information about registering and using notifications see Notifications
RootNodeRenderingNotification
The RootNodeRenderingNotification is published whenever a tree's root node is created.
Members:
TreeNode NodeFormCollection QueryStringstring TreeAlias
Usage:
TreeNodesRenderingNotification
The TreeNodesRenderingNotification is published whenever a list of child nodes are created.
Members:
TreeNodeCollection NodesFormCollection QueryStringstring TreeAlias
Usage:
MenuRenderingNotification
The MenuRenderingNotification is raised whenever a menu is generated for a tree node.
Members:
MenuItemCollection Menustring NodeIdFormCollection QueryStringstring TreeAlias
Usage:
Tree Actions and User Permissions
Last updated