I'm on Sitecore 8.1 and I have an item that has a multilist that allows a user to select all items under a site, but I want to exclude a couple items and their descendants. The basic tree structure looks like this:

Site Home
- Example Page 1
- Example Page 2
- Blog
-- Tags
--- Tag 1
--- Tag 2
--- Tag 3
-- Categories
--- Category 1
--- Category 2
--- Category 3
-- Blog Year
--- Blog Month
---- Blog Post 1
---- Blog Post 2
---- Blog Post 3
- Data
-- Data Folder 1
--- Data Folder 1 Item 1
--- Data Folder 1 Item 2
--- Data Folder 1 Item 3
-- Data Folder 2
--- Data Folder 2 Item 1
--- Data Folder 2 Item 2
--- Data Folder 2 Item 3
-- Site Settings
- Example Page 3
- Example Page 4
- Example Page 5

I currently use query:./ancestor-or-self::[@@templateid='{template ID of Site Home}']// to get all items under the site, but I can't figure out how to exclude the Blog item and all its descendants and the Data item and all its descendants.

What do I need to add to the end of that query to exclude the Blog item and its descendants and the Data item and its descendants?

2 Answers 2


I would suggest switching your field technology from a Multilist to a Treelist.

  1. The treelist allows the user to see the context of the object they're selecting. Considering that you're offering to allow the user to select from virtually any page on the site, allowing them to navigate the site to pick entries is a good idea.
  2. Programmatically, Treelist stores its data identically to Multilist, so you won't have to change any code that's reading the value.
  3. Instead of writing a complicated query, you can use Treelist's unique Datasource parameters to specify where the tree starts, which items are selectable, and even which items are visible.

https://getfishtank.ca/blog/treelist-data-source-hidden-functionality provides a good tutorial on these attributes, but for the casual user, they are described here.

This is an example of a configured Datasource value for a Treelist:


You're interested in the excludetemplatesfordisplay parameter, which you can use to hide the blog.

Consider excludetemplatesforselection when you need to let a user traverse an Item they shouldn't be able to add in order to get to descendant Items that are valid for selection.

For both of these values you can either supply the Template Name or the Template ID.

Don't forget to prefix your root Item's path with datasource=otherwise Sitecore will treat the path as an XPath statement and not process the querystring parameters at the end as expected.

There are considerably more features available, and I suggest reviewing the link above to get them all.


I was able to get my desired results by adding name()=ancestor-or-self::blog and name()=ancestor-or-self::data.

So my query ended up looking like query:./ancestor-or-self::*[@@templateid='{template ID of Site Home}']//*[name()=ancestor-or-self::blog and name()=ancestor-or-self::data]

It's using the item name instead of the template id, but it works for what I need.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.