On nearly every Sitecore site I’ve built, we’ve had a need to display 2 separate sections of the content tree in a single treelist field. The most common use-case being, having a folder to hold components local to the current item, and a shared folder for all items to use. Until now, I had never taken the time to take that code and make it generally applicable to any Sitecore site, opting to port the code from one site to another. So without further ado, the Multi-Root Treelist:
A View from the Content Editor:
On the desired field, from the Template Builder, select the field type named ‘Multi Root Treelist’. In the source field, define your datasources by path or by ID. For instance, for two datasources the syntax would be: Datasource=[path or ID of first root item]&Datasource2=[path or ID of second root item]. The source field also allows for relative paths. So, if you want one datasource to be relative to the current item, start the datasource with a ‘.’. For example, Datasource=./components identifies the components folder which is a child item of the current item.
So, by now you’re hopefully wondering, ‘That’s all well and good but how do I get my hands on this?’. As of the time of this post you can download the source from GitHub: https://github.com/OptimizedQuery/Sitecore.MultiRootTreelist. Installation is easy, just install the package found in the /sitecore directory and add the following lines to /App_Config/FieldTypes.config in your site’s web root.
<!-- Custom Field Types -->
<fieldType name="Multi Root Treelist" type="Sitecore.Data.Fields.MultilistField,Sitecore.Kernel" />
That’s all there is to it. Take it for a spin and let me know what you think.
**NOTE** Solution on GitHub references Sitecore v6.6 DLLs and .NET Framework v4.0.