XPath Queries for Multi Node Tree Picker

I want to set Multi Node Tree Picker to only show direct ancestors of the current page but the recommended query shows the entire tree

$current/ancestor::*

I would try to avoid xpath and use dynamic root. XPath is deprecated and removed in Umbraco 14+.

Good point, thank you @LuukPeters

You could try… $current/parent::* or $current/ancestor::*[1] (to note, XPath is 1-index based not zero).

1 Like

$current/ancestor::[1] and $current/parent:: both seem to filter to only the current page

$current/ancestor::* shows all the ancestors but their siblings as well and I don’t want the user to choose outside the section they are in. I could make a few for each root I guess but that seems very WET.

I also tried

$current/ancestor::*[not(preceding-sibling::*) and not(following-sibling::*)]

to exclude the siblings.

I think it has to be done with a custom query and Dynamic Root and more so v14 onwards I guess

Hi Dean :waving_hand:

The XPath for a Multi Node Tree Picker selects the parentnode of the subtree you want to select from… which nodes do you want to be able to select in the MNTP?

Or to put in another way: If your goal is to allow selecting any of the current node’s ancestors, I think you’ll need to install Lee’s Contentment package and use the DataList picker with the “Umbraco Content by XML” data source - that one lets you specify an XPath expression for the selectable nodes, which sounds like your goal?

/Chriztian

Thanks @greystate
I have created a nested navigation and allowed the user to choose the starting node.

This works fine out of the box but presents the user with the entire tree.
However, I was trying to restrict the choice to ‘only direct ancestors’.

I though there may be an ‘off the shelf’ option, but there is not, therefore I thought it could be easily done using xpath but the recommended queries I could find don’t seem to work with mntp.

As this is v13 I think I will wait and see what is possible in 14+.