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.
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.. 🙂