TreeList(Ex) field type with multiple roots

The built-in Sitecore TreeList and TreeListEx field types have quite many options and can be configured to become very user friendly for authors. However, I’ve been missing a few pieces to make it even more user friendly.

One of the things I’ve been missing the most is the ability to have multiple queries in the TreeList Source field, making it possible for authors to select items from multiple roots. This could for example be the ability to select items located close to the currently edited item or items shared on a site level or items shared on a tenant level. By default, you basically have to show the entire Sitecore tree in this scenario.

So what if we could have multiple Sitecore queries specified in the template field Source value? We could make a pipe separated list of queries that would return a smaller, more user friendly set of items. This is actually already supported in Sitecore, but only in the Datasource Location of a rendering.

TreeListEx with Multiple roots

Personally, I try to avoid changing how Sitecore works, create custom field types etc. But in this case I find the gain to be too good to avoid it. I hope Sitecore will incorporate this in future releases of the product.

With great help from my friend Jonas Hamnered, we took the built in controls and extended them so that one can provide a pipe separated list of Sitecore queries in the same way as the Datasource Location works on renderings. The code is available in this Github repository.

With these new fields you could for example create a dialog with a Source field looking something like this: datasource=./ancestor::*[@@templatekey='site']/Home|./ancestor::*[@@templatekey='tenant']/Folder|...&IncludeTemplateForSelection=... The screenshot above is built with such query.

The TreeList fields also comes with a few limitations. Dan Cruickshank has written a great post summarizing the common Source parameters. As he points out, some of the parameters allows specifying item names or item IDs. Unfortunately, some of the parameters only support item names.

Another limitation is that templates needs to be specified as specific templates – not inherited templates. This is also something I hope will be supported in future versions, as well as support inheritance in Sitecore queries.

Leave a Reply