How to configure different content nodes as part of TreeList or TreeListEx datasource?

Couple of days back I got a question whether we can have different parts or content tree or items based on different template as part of Single TreeList or TreeListEx field. First of all the difference between TreeList & TreeListEx is TreeList field always load the Content tree for you & TreeListEx only loads it on demand, so you should try to use TreeListEx in case of huge Content Tree.

Coming back to our initially query, I used to always provide the path of the parent Item in the Source field for TreeListEx and it used to load the Content tree considering the parent item as Root. Now even I wanted to explore if the requirement is possible so I started digging up and achieved it without any single line of code.

Lets see how can we achieve it. Follow the below steps.

Lets assume that I need to load Testimonials and Industries as part of TreeListEx field. I already have template and items for both Testimonials & Industries.

The below information will be required for creating the datasource:
Testimonial Template Name: Testimonial
Testimonial Parent item Template Name: Author Testimonial
Industries Template Name: Industry Page
Industries Parent item Template Name: Page

Create a template with only TreeListEx field and lets give the datasource field to display Testimonials and Industries:

The datasource field looks like below:
datasource=/sitecore/content&allowmultipleselection=yes&databasename=master&includetemplatesfordisplay=Author Testimonial,Testimonial,Industry Page,Page,Folder,Home Page&includetemplatesforselection=Author Testimonial,Testimonial,Industry Page,Page,Folder,Home Page

You can also exclude the unnecessary items using exclude*** attributes.

The main art of having different items from different part of content tree is to form the datasource perfectly. The below blog helped me to get away with my requirement.

Blog: https://getfishtank.ca/blog/treelist-data-source-hidden-functionality

All the attributes – datasource, allowmultipleslection, databasename, includetemplatesfordisplay, etc are explained properly in the above blog.

I hope this blog was helpful to play around the TreeList field.

Thank you.. Keep Learning.. Keep Sitecoring.. 🙂

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s